Jump to content

Recommended Posts

Posted

Changed _SQLite_QuerySingleResult() now uses 'sqlite3_get_table' API

(only indirect, a direct/faster version is on its way...)

Improved example_browser.au3

SQLite.zip

@randallc

_SQLite_QuerySingleColumn() would make no sence.

Just 'SELECT' only one column :lmao:

#include "sqlite.au3"
Local $aResult, $iRow,$iCol,$sErr
_SQLite_Startup()
_SQLite_Open()
_SQLite_QueryNoResult(-1,"CREATE TABLE test (a,b,c)")
_SQLite_QueryNoResult(-1,"INSERT INTO test VALUES ('1','2','3')")
_SQLite_QueryNoResult(-1,"INSERT INTO test VALUES ('1a','2a','3a')")
_SQLite_QueryNoResult(-1,"INSERT INTO test VALUES ('1b','2b','3b')")
_SQLite_GetTable2d (-1,"SELECT a FROM test",$aResult, $iRow,$iCol,$sErr)
MsgBox (0,"Column 'a'",_SQLite_Display2DResult($aResult,-1,True))
_SQLite_Close()
_SQLite_Shutdown()

@ptrex

sorry, i Couldnt re/compile litex.

maybe you'll ask one of the dev's :P

CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map
Posted

Hi @piccaso,

_SQLite_QuerySingleColumn() would make no sence.

Perhaps I mean rows;

If I have 100,000 rows and I only want 1000 in my listview,

Fetchdata too slow.

Gettable too big and slow for a small task.; or can I specify start and end rows?

I need GetRow to be faster than FetchData?

Thanks, Randall

Posted (edited)

@randallc

of course you can :P

#include "SQLite.au3"

Local $aResult, $iRow,$iCol,$sErr,$sSql

_SQLite_Startup()

_SQLite_Open(); Load :memory: database

_SQLite_QueryNoResult(-1,"CREATE TABLE test (a,b,c);"); Create a Table

for $i = 1 to 100

$sSql = $sSql & "INSERT INTO test VALUES (random(*),random(*),random(*));"

Next

_SQLite_QueryNoResult(-1,$sSql); INSERTing 100 Radndom Rows.

_SQLite_GetTable2d (-1,"SELECT ROWID,* FROM test LIMIT 6 OFFSET 4;",$aResult, $iRow,$iCol,$sErr)

MsgBox (0,"Using LIMIT & OFFSET",_SQLite_Display2DResult($aResult,0,True))

_SQLite_GetTable2d (-1,"SELECT ROWID,* FROM test WHERE ROWID >= '5' AND ROWID <= '10'; ",$aResult, $iRow,$iCol,$sErr)

MsgBox (0,"Using WHERE & ROWID",_SQLite_Display2DResult($aResult,0,True))

_SQLite_Close()

_SQLite_Shutdown()

note that:

ROWID is always present ( integer primary key )

and you dont have to 'SELECT' it to use it in 'WHERE' Clause

I did it just for the example

and if you want to 'SELECT' it you have to specify it ( * doesent match that one )

check doc's on SELECT for LIMIT, OFFSET..

Edited by piccaso
CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map
Posted

Great!

Sorry I don't understand the SQL syntax yet; I keep hoping I'll get familiar with it the more I use it.

This should solve most of my speed issues; Except for the total table write to text or transfer to Excel, which will remain at about 1/3 speed, I think; if that is the only dosadvantage of the DLL method and we can change version easily, it certainly looks the most attractive depite some speed issues.

Best, Randall

Posted (edited)

@randallc

its faster now :P

Using LIMIT and removing ' If $iRowCnt > GUICtrlRead($Tab1combo1) Then ExitLoop '...

and some little things i dont remeber... (use windiff if you want to know :lmao: )

sorry, i'm having a hard time reading your code, still working on it...

[edit] uploaded new one

Edited by piccaso
CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map
Posted (edited)

Fantastic!

Sorts listviews of limited numbers at least as fast as the litex wrapper one.

It's only going to be a problem if you try to open all of a huge database instead of a portion (eg blink's database with OWC 270,000 x 700!)

I will manage to avoid that except when re-saving a sorted large file, for instance [still 30% the speed of wrapper for that]

btw to get the correct column sorting in listview (the one to the left of that clicked sorts now)

$i_OrderNumber&=1

at start of each getdata.

I will post again later.

Thanks again,

Randall

[EDIT - I guess we can apply the same principles to the gettable calls for getting the whole file.....

More to come...?]

Edited by randallc
Posted

Hi @ piccaso,

No - the only reason the DLL sqlite can catch up in listview is because of the GUIListView Create Item slowing down the wrapper;

All functions other than listview and insertion will be 3-4x faster with the wrapper sqlite if we have to get one item at a time and loop through them in AutoIt..

oh well... I'd be interested to hear if you come up with anything else.

Best, Randall

Posted

com is faster, i cant change that :lmao:

if you look at other sqlite browsers that use the dll you'll see that they are even faster, but keep in mind that we are using a interpreter here...

so you can only choose between fast com and an old version with bugs

or a latest version :P

dependig on what you want to do.

i have some ideas but i dont think it will beat the com wrapper in speed...

CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map
Posted (edited)

Hi,

I agree;

1. Gettable needs to do its reading in chunks of, say, 10000 (or even 100,000) as I can jam memory with 10^6 rows at present.

2. Similarly the string concat for a pointer on "insert table" I have had to limit the chunks to 100,000 in my script.

3. I can emulate the speed (nearly) of com for a "total" gettable by checking if "sqlite.exe" is in appropriate directory, and using that instead (If present, fileinstall..) (do a dump and modify the text file produced); if not present, accept getable speed. This seems to give flexibility to use current sqlite by dll and option of speed for people with a big task.

Let me know if you have other thoughts...

Best, Randall

Edited by randallc
Posted (edited)

@piccaso;

here's the example dump and process; [assumes "sqlite.exe" in include directory]

10000 rows wrapper (litex COM) 5800;// dump (sqlite.exe) 6900 // GetTable (Autoit DLL call) 22500 //on a slowish machine

best, randall

Edited by randallc
Posted (edited)

@randallc

could you post getTable example too...

thanks

btw:

i think wrapping sqlite.exe is better than using the com wrapper (no offense ptrex :P )

because you can the latest version...

trids started something like this

http://www.autoitscript.com/forum/index.ph...indpost&p=61614

Edited by piccaso
CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map
Posted

@randallc

you dont have to process it...

.mode MODE ?TABLE? Set output mode where MODE is one of:

csv Comma-separated values

column Left-aligned columns. (See .width)

html HTML <table> code

insert SQL insert statements for TABLE

line One value per line

list Values delimited by .separator string

tabs Tab-separated values

tcl TCL list elements

Try this: (dumped 10000 rows in 150msec)
Local $sDumpFile = "dump.csv"
Local $sDbFile = "sqlite3.db"
Local $sDbTable = "test"
Local $sInstructionsFile = "sqlite.inst"

Local $nTimer,$hFp
if FileExists($sDumpFile) Then FileDelete($sDumpFile)
if FileExists($sInstructionsFile) Then FileDelete($sInstructionsFile)   

$hFp = FileOpen($sInstructionsFile,2)
if $hFp = -1 Then Exit -1
FileWriteLine($hFp,".output " & $sDumpFile)
FileWriteLine($hFp,".mode tabs " & $sDbTable)
FileWriteLine($hFp,"SELECT * FROM " & $sDbTable & ";")
FileClose($hFp)

$nTimer = TimerInit()
RunWait(@ComSpec & " /c sqlite3.exe " & $sDbFile & " < " & $sInstructionsFile,@WorkingDir,@SW_HIDE)
MsgBox (0,"Timer",TimerDiff($nTimer))
CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map
Posted (edited)

@piccaso

Very fast!

Can you get the rows in lines by this method? -All seems to be tabs. [EDIT; no - opens OK in Word, not notepad; tabs and lines!]

I will post GetTable; but I have not yet fixed the grouping there (I have done in make table)

Best, randall

[EDIT; Ignore query- opens OK in Word, not notepad; tabs and lines!] - fantastic; I'll explore more for my purposes

Edited by randallc
Posted (edited)

Hi,

Old time and new time write to console after "export to Text button"

DLL /Com wrapper / sqliteExe

11800 / 3300 / 700!

Best , Randall

PS @piccaso, are you thinking you can use this for all the functions, or mixing DLL calls with sqlite.exe?

Edited by randallc
Posted (edited)

@randallc

i'm allready working on a wrapping function.

but updateing a listview will be slower that way (i think)

it generates html too, maybe using an ie obj. is faster here...

time wil tell...

but you wont be able to mix it, just use it on the same db...

Edited by piccaso
CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map
Posted (edited)

Hi,

I am watching, but not sure where you are going still; you are in fact using a mixture now within one script?

I am trying to avoid filling memory with arrays or large strings;

how will you decide if a file is too big for a fileread?;

$sOutput = FileRead($sOutputFile,FileGetSize($sOutputFile))

and what will you do instead?

See also my switch in "Write" function below depending whether sqlite.exe is present or not,

and the loop for over 100,000 lines (should I calculate memory size using columns as well... oh well...)

Edited by randallc
Posted

@picasso

the name may change, it sounds silly... any sugestions?

SQLite.exe is a commandline tool of SQLite. Why not call it _SQL_Cmd or SQL_CmdTool,

at least call the beast the name it already has.

I haven' t tested it yet will do for sure this week.

Thanks

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...