Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VFP ODBC driver
Message
 
 
À
03/09/2019 12:22:28
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Divers
Thread ID:
01670527
Message ID:
01670563
Vues:
63
>>
>>The problem with VFPOLEDB is, that I cannot query directly into a cursor, but ADO Dataset. When I have the dataset, I would need to create a cursor from that by loop and insert, but it's a huge table. So the only reason I used ODBC was that I can setup an async connection and get the result immediately, while scrolling and fetching continuously, so the user can start working without waiting for 5 minutes. But perhaps there is another way to use OLEDB that I have not considered?
>
>I just made a quick test with a 910K rows table, it displayed the browse screen under 3 seconds on my System. Here is the code:
>
>
>start = SECONDS()
>Local loCursor, lcConStr
>
>lcConStr = 'Provider=SQLNCLI11.0;Trusted_connection=Yes;Server=.\SQLExpress;Database=Sampledb'
>loCursor = Createobject('CaGeneric',m.lcConStr)
>
>With loCursor
>  .Alias          = 'myTable'
>  TEXT TO .SelectCmd  noshow
>SELECT * FROM hugeTable
>  ENDTEXT
>Endwith
>If loCursor.QueryFill()
>  Select (loCursor.Alias)
>  Browse LAST nowait
>Endif
>? SECONDS()-m.start
>Define Class CaGeneric As CursorAdapter
>  CompareMemo = .F.
>  FetchAsNeeded = .T.
>  FetchSize = 100
>  FetchMemo = .T.
>  BatchUpdateCount = 100
>  WhereType = 1
>  AllowSimultaneousFetch = .T.
>  MapVarchar = .T.
>  MapBinary = .T.
>  BufferModeOverride = 5
>
>  DataSourceType = 'ADO'
>  InsertCmdDataSourceType = 'ADO'
>  UpdateCmdDataSourceType = 'ADO'
>  DeleteCmdDataSourceType = 'ADO'
>
>  Procedure Init(tcConnectionString)
>    Set Multilocks On
>    Local loConnDataSource
>    loConnDataSource = Createobject('ADODB.Connection')
>    loConnDataSource.ConnectionString = m.tcConnectionString
>    loConnDataSource.Open()
>    This.Datasource = Createobject('ADODB.RecordSet')
>    This.Datasource.CursorLocation   = 3  && adUseClient
>    This.Datasource.LockType         = 3  && adLockOptimistic
>    This.Datasource.ActiveConnection = m.loConnDataSource
>    loCommand = Createobject('ADODB.Command')
>    loCommand.ActiveConnection = loConnDataSource
>    This.AddProperty('oCommand',loCommand)
>    Store loCommand To ;
>      This.UpdateCmdDataSource,;
>      This.InsertCmdDataSource,;
>      This.DeleteCmdDataSource
>  Endproc
>
>  Procedure MakeUpdatable(tcTableName,tckeyField,tlDoNotIncludeKey)
>    This.Tables = m.tcTableName
>    This.KeyFieldList = m.tckeyField
>    Local ix, lnUpdateableFCount
>    lnUpdateableFCount = Fcount(This.Alias)-Iif(This.DataSourceType='ADO',1,0) && last one is ADOBOOKMARK
>    For ix = 1 To m.lnUpdateableFCount
>      If !m.tlDoNotIncludeKey Or !(Upper(Field(m.ix,This.Alias,0)) == Upper(m.tckeyField))
>        This.UpdatableFieldList = This.UpdatableFieldList + ;
>          IIF(Empty(This.UpdatableFieldList),'',',') + ;
>          FIELD(m.ix,This.Alias,0)
>      Endif
>      This.UpdateNameList = This.UpdateNameList + ;
>        IIF(Empty(This.UpdateNameList),'',',') + ;
>        TEXTMERGE('<<FIELD(m.ix,this.Alias,0)>> <<m.tcTableName>>.<<FIELD(m.ix,this.Alias,0)>>')
>    Endfor
>  Endproc
>
>  Procedure QueryFill()
>    Local llSuccess
>    If This.DataSourceType ="ADO"
>      llSuccess = This.CursorFill(.F.,.F.,0,This.oCommand)
>    Else
>      llSuccess = This.CursorFill(.F.)
>    Endif
>    If !m.llSuccess
>      If This.DataSourceType ="ADO"
>        lcMessage = This.oCommand.CommandText + Chr(13) + This.GetErrorExplanation()
>      Else
>        lcMessage = This.GetErrorExplanation()
>      Endif
>      Messagebox(m.lcMessage)
>    Endif
>    Return m.llSuccess
>  Endproc
>
>  Procedure GetErrorExplanation
>    Local lcError,ix
>    Local Array aWhy[1]
>    Aerror(aWhy)
>    lcError = ""
>    For ix = 1 To 7
>      lcError = m.lcError + Transform(aWhy[m.ix]) + Chr(13)
>    Endfor
>    Return m.lcError
>  Endproc
>Enddefine
>
>
>And 910K rows table was created from Customers like this:
>
>WITH TALLY AS 
>(
>select top(10000) row_number() over (order by t1.object_id) as N
>from sys.all_columns t1 cross join sys.all_columns t2
>)
>SELECT tally.N as grp, c.*
>into hugeTable
>FROM nORTHWIND..CUSTOMERS C
>CROSS JOIN tally;
>
Thanks a lot, this is indeed the way to go.
Christian Isberner
Software Consultant
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform