Example: /SQL/SQLite Fetch rows bulk

Online Documentation   -   Statistics   -   FAQ   -   Plugin Parts (All, Dependencies)   -   Class hierarchy

New in Version 22.2 22.3 22.4 22.5 23.0 23.1 23.2 23.3 23.4 23.5 24.0 24.1

The list of the   topics,   classes,   interfaces,   controls,   modules,   global methods by category,   global methods by name,   screenshots,   licenses   and   examples.

Platforms to show: All Mac Windows Linux Cross-Platform

/SQL/SQLite Fetch rows bulk


Required plugins for this example: MBS SQL Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /SQL/SQLite Fetch rows bulk

This example is the version from Thu, 6th Apr 2016.

Project "SQLite Fetch rows bulk.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open() // use internal sqlite library call InternalSQLiteLibraryMBS.Use // now add that file to database dim con as SQLConnectionMBS dim cmd as SQLCommandMBS try con = new SQLConnectionMBS // connection object cmd = new SQLCommandMBS // create command object // where is the library? 'con.Option(con.kOptionLibrarySQLite) = "/usr/lib/libsqlite3.0.dylib" // connect to database dim path as string if TargetMacOS then path = "/tmp/test.db" // put the database in the temporary folder else path = "test.db" // for Windows and Linux in the current folder the application is inside. end if con.Connect(path,"","",SQLConnectionMBS.kSQLiteClient) // associate a command with connection // connection can also be specified in SACommand constructor cmd.Connection=con // Create and Insert test table if HaveSampleData(cmd)=False then CreateSampleData(cmd, 200000) con.Commit end if dim start, finish as integer MsgBox "Reading data without bulk support (default)..." start=ticks cmd.setCommandText "Select * from TEST_BULK" cmd.Execute while cmd.FetchNext // go over all rows wend finish=ticks MsgBox "Time in seconds: "+str((finish-start)/60.0)+" seconds." dim nBulkSize as integer = 1000 msgbox "Reading data with bulk support (Size="+str(nBulkSize)+")..." start=ticks cmd.setCommandText "Select * from TEST_BULK" cmd.Option("PreFetchRows") = str(nBulkSize) cmd.Execute while cmd.FetchNext // go over all rows wend finish=ticks MsgBox "Time in seconds: "+str((finish-start)/60.0)+" seconds." catch r as SQLErrorExceptionMBS // SAConnection::Rollback() // can also throw an exception // (if a network error for example), // we will be ready try // on error rollback changes if con<>nil then con.rollback end if catch x as SQLErrorExceptionMBS // ignore end try // show error message MsgBox r.message end try End EventHandler
Sub CreateSampleData(cmd as SQLCommandMBS, nRows as integer) MsgBox "Creating test table..." cmd.setCommandText("CREATE TABLE TEST_BULK (FINTEGER INTEGER NOT NULL, FVARCHAR20 VARCHAR(20), PRIMARY KEY (FINTEGER))") cmd.Execute MsgBox "Populating test table (rows="+str(nrows)+")..." cmd.setCommandText "BEGIN" cmd.Execute cmd.setCommandText("Insert into TEST_BULK (FINTEGER, FVARCHAR20) values (:1, :2)") for i as integer = 1 to nRows cmd.Param(1).setAsLong i cmd.Param(2).setAsString "VC"+str(i) cmd.Execute next cmd.setCommandText "COMMIT" cmd.Execute MsgBox str(nRows)+" inserted." End Sub
Function HaveSampleData(cmd as SQLCommandMBS) As Boolean try cmd.setCommandText "Select * from TEST_BULK" cmd.Execute if cmd.FetchNext then Return true end if catch s as SQLErrorExceptionMBS Return false // no table TEST_BULK end try End Function
End Class
Class Window1 Inherits Window
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
End Project

See also:

The items on this page are in the following plugins: MBS SQL Plugin.


💬 Ask a question or report a problem