1 Son düzenleyen, mmmiko (03.06.2021 22:08:03)

Konu: SQL SERVER / VFP7.O DOSYALARI byte array OLARAK TABLODA TUTMAK

Arkadaşlar merhaba.

Bmp, jpg, pdf, excel vb dosyaları byte array olarak sql server veri tabanı tablosunda tutmak, gerektiğinde tekrar Bmp, jpg, pdf, excel e dönüştürmek ve raporlarda formlarda kullanmak hususunda üstadlardan yardım alabilir miyim.

Çetin Hocamın aşağıdaki kodu ile BMP dosyalarını veritabanı tablosuna yazıp select ile alarak ekranda gösterdim ancak dosyayı fiziksel olarak oluşturmam gerekti.

Dosyayı diske yazmadan bellekte oluşturmak ve kullanmak ve bunları VFP9.0 yerine VFP7.0 ile yapabilme imkanı konusunda yardım alabilir miyim.

* Test Data yarat - Create test data
lnHandle = Sqlstringconnect('Driver={SQL Native Client};Server=.\SQLExpress;Trusted_Connection=yes')
TEXT TO lcCreate noshow
IF NOT EXISTS ( SELECT  name
                FROM    sys.databases
                WHERE   name = N'ImageDb' )
    Create DATABASE [ImageDb]
ENDTEXT
SQLExec(m.lnHandle,m.lcCreate)
SQLExec(m.lnHandle,'Use ImageDb')
?SQLExec(m.lnHandle,'Create Table ImageTable1'+;
  ' (pkId uniqueidentifier rowguidcol default NewID(),'+;
  ' fName varchar(20),lName varchar(20),'+;
  ' personPicture image)')
?SQLExec(m.lnHandle,'Create Table ImageTable2'+;
  ' (pkId uniqueidentifier rowguidcol default NewID(),'+;
  ' fName varchar(20),lName varchar(20),'+;
  ' personPicture varbinary(max))')


lcImagePath = _samples + 'data\graphics'
For ix=1 To Adir(aFiles, Addbs(m.lcImagePath)+'*.*')
  Image = Createbinary(Filetostr(Addbs(m.lcImagePath)+aFiles[m.ix,1]))
  fname = Proper(Left(aFiles[m.ix,1],4))
  lName = Proper(Substr(aFiles[m.ix,1],5,4))

  ?SQLExec(m.lnHandle, ;
    "insert into ImageTable1 (fName,lName,personPicture)"+;
    " values (?m.fname,?m.lname,?m.image)")
  ?SQLExec(m.lnHandle, ;
    "insert into ImageTable2 (fName,lName,personPicture)"+;
    " values (?m.fname,?m.lname,?m.image)")
Endfor
SQLDisconnect(m.lnHandle)
* Test Data yarat - Create test data

* Form ile goster - Show on a form
Public oForm
oForm = Createobject('myForm')
oForm.Show

Define Class myForm As Form
  DataSession = 2
  Height = 400
  Width = 800

  Add Object myGrid1 As Grid With Height = 180, Top =  10,Width = 400, RecordSource = 'Sample1'
  Add Object myGrid2 As Grid With Height = 180, Top = 210,Width = 400, RecordSource = 'Sample2'
  Add Object myImage1 As Image With Left = 410,Top = 0
  Add Object myImage2 As Image With Left = 410,Top = 300

  Procedure Load
    lnHandle = Sqlstringconnect('Driver={SQL Native Client};Server=.\SQLExpress;Trusted_Connection=yes')
    CursorSetProp("MapBinary",.T.,0)
    SQLExec(m.lnHandle,'select * from ImageDb..ImageTable1','Sample1')
    SQLExec(m.lnHandle,'select * from ImageDb..ImageTable2','Sample2')
    SQLDisconnect(m.lnHandle)
  Endproc

  Procedure myGrid1.AfterRowColChange
    Lparameters nColIndex
    If This.RowColChange%2 = 1
      Thisform.myImage1.PictureVal = Sample1.personPicture
    Endif
  Endproc

  Procedure myGrid2.AfterRowColChange
    Lparameters nColIndex
    If This.RowColChange%2 = 1
      Thisform.myImage2.PictureVal = Sample2.personPicture
    Endif
  Endproc

  Procedure Init
    Thisform.myImage1.PictureVal = Sample1.personPicture
    Thisform.myImage2.PictureVal = Sample2.personPicture
  Endproc
Enddefine


You would use ACE or Jet driver for Access. Check:

http://www.foxite.com/archives/0000153776.htm

Also here is a sample MDB browser form:

Public oForm
oForm = Createobject('myForm')
oForm.Show()

Define Class myForm As Form
  Height = 450
  Width = 850
  DataSession=2
  Caption='Show Access Data'

  Add Object lblAccess As Label With ;
    Caption = "Access Database", ;
    Left = 10, Top = 15, Width = 100

  Add Object txtMDBlocation As TextBox With ;
    Left = 112, Top = 12, Width = 520

  Add Object cmdBrowse As CommandButton With ;
    Top = 10, Left = 640, Caption = "Browse", Autosize=.t.

  Add Object lblTables As Label With ;
    Caption = "Tables", Left = 20, Top = 40, Width = 40

  Add Object lstTables As ListBox With ;
    Height = 400, Left = 65, Top = 40, Width = 265

  Add Object grdShow As Grid With ;
    Height = 400, Left = 340, Top = 40, Width = 500

  Procedure listtables
    Local lnConnHandle,lcMDB
    With This.txtMDBlocation
      If Empty(.Value) Or !File(.Value)
        Return
      Endif
      lcMDB = Trim(.Value)
    Endwith

    lnConnHandle = ;
     Sqlstringconnect("Driver={Microsoft Access Driver (*.mdb)};"+;
                     "Uid=Admin;DBQ="+m.lcMDB)
    SQLTABLES(m.lnConnHandle, ['TABLE'], 'crsTables')
    SQLDISCONNECT(m.lnConnHandle)
    Select crsTables
    This.lstTables.Clear()
    Scan
      This.lstTables.AddItem(crsTables.table_name)
    Endscan
  Endproc


  Procedure txtMDBlocation.LostFocus
    Thisform.listtables()
  Endproc


  Procedure cmdBrowse.Click
    This.Parent.txtMDBlocation.Value = Getfile('MDB','','',0,'Select Access Database')
    Thisform.listtables()
  Endproc


  Procedure lstTables.InteractiveChange
    Local lnConnHandle,lcMDB,lcSQL
    With This.Parent.txtMDBlocation
      If Empty(.Value) Or !File(.Value)
        Return
      Endif
      lcMDB = Trim(.Value)
    Endwith

    lcSQL = 'select * from "'+Trim(This.Value)+'"'
    lnConnHandle = ;
     Sqlstringconnect("Driver={Microsoft Access Driver (*.mdb)};"+;
                     "Uid=Admin;DBQ="+m.lcMDB)
    SQLEXEC(m.lnConnHandle,m.lcSQL,'crsLocal')
    SQLDISCONNECT(m.lnConnHandle)
    With This.Parent.grdShow
      .ColumnCount = -1
      .RecordSource = 'crsLocal'
    Endwith
  Endproc
Enddefine


Note: Latter use ODBC.

Cetin Basoz

2

Re: SQL SERVER / VFP7.O DOSYALARI byte array OLARAK TABLODA TUTMAK

Selamlar;
Ben aşağıdaki kod ile Image1 de resimleri gösterbiliyorum.

Veri tabanına ekleme

Lcsicilno='1518'
    Lcresim=Getpict("jpg")
    If !Empty(Lcresim)
        image1 = Createbinary(Filetostr(Lcresim)) && works for any type of file to store as is
        fname = "JPG"
        lName = Lcsicilno
        If Reccount('Crsicilresimvarmi')>0
            x1=mySQLExec(appcmds.lnHandle,"UPDATE sicilresimleri SET personelresim=?m.image1 WHERE dosyaadi=?Lcsicilno")
            Wait Window "Güncellendi" Nowa
        Else
            x2=SQLExec(appcmds.lnHandle,"INSERT INTO sicilresimleri(dosyaadi,dosyauzanti,personelresim) values (?m.lname,?m.fname,?m.image1)")
            Wait Window "Eklendi" Nowa
        Endif
    Endif


Ekranda göstermek içinde

Cursor oluşturmak için

CursorSetProp("MapBinary",.T.,0) 
SQLExec(appcmds.lnHandle,'select * from sicilresimleri','sicilresimleri')
CursorSetProp("MapBinary",.F.,0)

Ekranda göstermek için
Thisform.Image1.PictureVal = sicilresimleri.personelresim

Dosyaya çevirme
StrToFile(sicilresimleri.personelresim,"aaa.jpg")

Bilmediğin Neyse Yanıldığındır.

3

Re: SQL SERVER / VFP7.O DOSYALARI byte array OLARAK TABLODA TUTMAK

Selamlar;
Ben aşağıdaki kodu kullanıyorum..
Umarım faydalı olur.


*Veri tabanına ekleme
Lcsicilno='1518'
Lcresim=Getpict("jpg")
If !Empty(Lcresim)
    image1 = Createbinary(Filetostr(Lcresim)) && works for any type of file to store as is
    fname = "JPG"
    lName = Lcsicilno
    If Reccount('Crsicilresimvarmi')>0
        x1=mySQLExec(appcmds.lnHandle,"UPDATE sicilresimleri SET personelresim=?m.image1 WHERE dosyaadi=?Lcsicilno")
        Wait Window "Güncellendi" Nowa
    Else
        x2=SQLExec(appcmds.lnHandle,"INSERT INTO sicilresimleri(dosyaadi,dosyauzanti,personelresim) values (?m.lname,?m.fname,?m.image1)")
        Wait Window "Eklendi" Nowa
    Endif
Endif


*Ekranda göstermek içinde
Cursor oluşturmak için
CursorSetProp("MapBinary",.T.,0)
SQLExec(appcmds.lnHandle,'select * from sicilresimleri','sicilresimleri')
CursorSetProp("MapBinary",.F.,0)

*Ekranda göstermek için
Thisform.Image1.PictureVal = sicilresimleri.personelresim

*Dosyaya çevirme
StrToFile(sicilresimleri.personelresim,"aaa.jpg")

Bilmediğin Neyse Yanıldığındır.

4

Re: SQL SERVER / VFP7.O DOSYALARI byte array OLARAK TABLODA TUTMAK

Teşekkür ederim.

5

Re: SQL SERVER / VFP7.O DOSYALARI byte array OLARAK TABLODA TUTMAK

Teşekkür ederim.