Jump to content
FrancescoDiMuro

Quotes in query SQLite...

Recommended Posts

FrancescoDiMuro

Hi guys! How are you? Hope you're fine :)
I'm trying to insert a text that contains quotes in a SQLite database, and I don't know how to do.
I tried with:

Local $sString = "1P6AV2104'0HA04'0AA0"
StringReplace($sString, "'", "''")

but I didn't managed to, obtaining this error:

--> Error:    unrecognized token: "0HA04"

How can I manage to solve this problem? Thanks :) 


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

ALWAYS GOOD TO READ:

In case I am violating some pseudo Forum rule, or I am doing something wrong, I want let you know that I'm not doing this on purpose, and for this, I kindly ask you to send me a private message about the "bad content" I posted, in order to edit/remove it, and to not be warned wrongly.
Thanks in advance.

 

Share this post


Link to post
Share on other sites
jchd

Post the code.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
FrancescoDiMuro
23 hours ago, jchd said:

Post the code.

_SQLite_Exec($hDatabase, "CREATE TABLE Magazzino_Siemens (ID, MARCA, QUANTITA, SCAFFALE, DESCRIZIONE, COSTO, NOTE, INFO, BARCODE, DATA_INSERIMENTO, DATA_PRELIEVO, DATA_MODIFICA);")
    $oWorkbook.Sheets("Magazzino Siemens").Activate
    Local $aRisultatoSiemens = _Excel_RangeRead($oWorkbook, Default, $oWorkbook.ActiveSheet.Usedrange.Columns("A:L"), 1, True)
    If(@error) Then
        MsgBox($MB_ICONERROR, "Errore!", "Errore: " & @error)
    EndIf
    For $i = UBound($aRisultatoSiemens) - 1 To 4 Step -1
        If($aRisultatoSiemens[$i][4] = "") Then _ArrayDelete($aRisultatoSiemens, $i)
    Next
    For $i = 3 To UBound($aRisultatoSiemens) - 1
        _SQLite_Exec($hDatabase, "INSERT INTO Magazzino_Siemens (ID, MARCA, QUANTITA, SCAFFALE, DESCRIZIONE, COSTO, NOTE, INFO, BARCODE, DATA_INSERIMENTO, DATA_PRELIEVO, DATA_MODIFICA) " & _
                                       "VALUES (" & _
                                        "'" & $aRisultatoSiemens[$i][0] & "'" & "," & "'" & $aRisultatoSiemens[$i][1] & "'" & "," & "'" & $aRisultatoSiemens[$i][2] & "'" & "," & _
                                        "'" & $aRisultatoSiemens[$i][3] & "'" & "," & "'" & $aRisultatoSiemens[$i][4] & "'" & "," & "'" & $aRisultatoSiemens[$i][5] & "'" & "," & _
                                        "'" & $aRisultatoSiemens[$i][6] & "'" & "," & "'" & $aRisultatoSiemens[$i][7] & "'" & "," & "'" & $aRisultatoSiemens[$i][8] & "'" & "," & _
                                        "'" & $aRisultatoSiemens[$i][9] & "'" & "," & "'" & $aRisultatoSiemens[$i][10] & "'" & "," & "'" & StringReplace($aRisultatoSiemens[$i][11], "'", "''") & "'" & ");")
    Next

Thank you :) 


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

ALWAYS GOOD TO READ:

In case I am violating some pseudo Forum rule, or I am doing something wrong, I want let you know that I'm not doing this on purpose, and for this, I kindly ask you to send me a private message about the "bad content" I posted, in order to edit/remove it, and to not be warned wrongly.
Thanks in advance.

 

Share this post


Link to post
Share on other sites
jchd

You really should specify datatypes in the create table statement, else you may have issues.

The function _SQLite_FastEscape() deals with single quote(s) in text fields.

Don't wrap numeric fields inside single quotes.

Use a transaction to group your inserts.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
FrancescoDiMuro

@jchd

Could you please post an example of what you said? Thanks and have a good day :)

EDIT:

I would like to understand your phrase too:

"Use a transaction to group your inserts."

I am writing from my smartphone, so, sorry If I didn't quote you in right way :) Thanks :)

 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

ALWAYS GOOD TO READ:

In case I am violating some pseudo Forum rule, or I am doing something wrong, I want let you know that I'm not doing this on purpose, and for this, I kindly ask you to send me a private message about the "bad content" I posted, in order to edit/remove it, and to not be warned wrongly.
Thanks in advance.

 

Share this post


Link to post
Share on other sites
jchd
_SQLite_Exec($hDatabase, _
    "CREATE TABLE Magazzino_Siemens (" & _  ; here Siemens is data put in schema name; will make your life much harder
        "ID integer primary key, " & _      ; wild guess it's an integer id
        "MARCA text, " & _
        "QUANTITA numeric, " & _            ; can it be float? if not, use INT instead
        "SCAFFALE text, " & _       
        "DESCRIZIONE text, " & _
        "COSTO numeric, " & _               ; prefer prices as integers (scale accordingly)
        "NOTE text, " & _
        "INFO text, " & _
        "BARCODE text, " & _
        "DATA_INSERIMENTO text, " & _       ; beware that Excel dates are "special"
        "DATA_PRELIEVO text, " & _          ; convert them to UTC ISO (yyyy-mm-dd)
        "DATA_MODIFICA text" & _
    ");" _
)
$oWorkbook.Sheets("Magazzino Siemens").Activate
Local $aRisultatoSiemens = _Excel_RangeRead($oWorkbook, Default, $oWorkbook.ActiveSheet.Usedrange.Columns("A:L"), 1, True)
If (@error) Then
    MsgBox($MB_ICONERROR, "Errore!", "Errore: " & @error)
Else
    For $i = UBound($aRisultatoSiemens) - 1 To 4 Step -1
        If($aRisultatoSiemens[$i][4] = "") Then _ArrayDelete($aRisultatoSiemens, $i)
    Next
    _SQLite_Exec($hDatabase, "begin")
    For $i = 3 To UBound($aRisultatoSiemens) - 1
        _SQLite_Exec($hDatabase, _
            "INSERT INTO Magazzino_Siemens (" & _
                "ID, " & _
                "MARCA, " & _
                "QUANTITA, " & _
                "SCAFFALE, " & _
                "DESCRIZIONE, " & _
                "COSTO, " & _
                "NOTE, " & _
                "INFO, " & _
                "BARCODE, " & _
                "DATA_INSERIMENTO, " & _
                "DATA_PRELIEVO, " & _
                "DATA_MODIFICA" & _
            ") VALUES (" & _
                $aRisultatoSiemens[$i][0] & "," & _                         ; ID
                _SQLite_FastEscape($aRisultatoSiemens[$i][1]) & "," & _     ; MARCA
                $aRisultatoSiemens[$i][2] & "," & _                         ; QUANTITA
                _SQLite_FastEscape($aRisultatoSiemens[$i][3]) & "," & _     ; SCAFFALE
                _SQLite_FastEscape($aRisultatoSiemens[$i][4]) & "," & _     ; DESCRIZIONE
                $aRisultatoSiemens[$i][5] & "," & _                         ; COSTO
                _SQLite_FastEscape($aRisultatoSiemens[$i][6]) & "," & _     ; NOTE
                _SQLite_FastEscape($aRisultatoSiemens[$i][7]) & "," & _     ; INFO
                _SQLite_FastEscape($aRisultatoSiemens[$i][8]) & "," & _     ; BARCODE               | those last 4 fields are unlikely
                _SQLite_FastEscape($aRisultatoSiemens[$i][9]) & "," & _     ; DATA_INSERIMENTO      | to contain single quotes
                _SQLite_FastEscape($aRisultatoSiemens[$i][10]) & "," & _    ; DATA_PRELIEVO         | but this is bulletproof
                _SQLite_FastEscape($aRisultatoSiemens[$i][11]) & _          ; DATA_MODIFICA         | convert dates before!!!
            ");" _
        )
    Next
    _SQLite_Exec($hDatabase, "commit")
EndIf

 

  • Like 1

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
FrancescoDiMuro

@jchd
Hey! It works :) Thanks :)

ID it's not numeric, so I processed it as text...
COSTO would be real, but when I do the "INSERT", an error appears in corrispondence of the field "COSTO"... So I am trrating it as text...
Just to know... Even when I do some UPDATE I have to do proceed with "_SQLite_FastEscape()" function? A big thank you :D

EDIT:

Costo is effectively REAL, because it's like € xx,xx...
So, I would declare it as REAL and don't do pass it to the _SQLite_FastEscape() function, am I right?
If you could me explain these things, I'd be very happy and, if you need some example of what I'm meaning, just ask :)

Again thanks :D 

 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

ALWAYS GOOD TO READ:

In case I am violating some pseudo Forum rule, or I am doing something wrong, I want let you know that I'm not doing this on purpose, and for this, I kindly ask you to send me a private message about the "bad content" I posted, in order to edit/remove it, and to not be warned wrongly.
Thanks in advance.

 

Share this post


Link to post
Share on other sites
jchd
1 hour ago, FrancescoDiMuro said:

Costo is effectively REAL, because it's like € xx,xx...

A real for a computer is of the form 9999.9999 with no € sign and a dot as decimal point, not a comma. You can reformat the cost value so that is fits what is expected for a real. Integers and reals don't need escaping, clrealy, since they can't contain single quotes.

Update needs escaping text like insert and for the very same reason.

Anyway you may still want to reconsider your table design to avoid maintaining separate tables for different manufacturers/suppliers (if those tables have the same fields). IIRC you mentionned Siemens and Rockwell or something. Do those tables have the same structure?

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
FrancescoDiMuro
14 hours ago, jchd said:

A real for a computer is of the form 9999.9999 with no € sign and a dot as decimal point, not a comma. You can reformat the cost value so that is fits what is expected for a real. Integers and reals don't need escaping, clrealy, since they can't contain single quotes.

Update needs escaping text like insert and for the very same reason.

Anyway you may still want to reconsider your table design to avoid maintaining separate tables for different manufacturers/suppliers (if those tables have the same fields). IIRC you mentionned Siemens and Rockwell or something. Do those tables have the same structure?

Good morning @jchd:)
For the first question, I should replace the € with "", and, " , " with "."... Then, I could proceed with the "REAL" format for the field COSTO.
Fot the second question, I answer "Yes, all 4 tables ( are 4, not 2 as I, maybe, didn't explain in the right way ), have the same format... But, I preferred to keep them separate because, If I have to make a query, the SQLite has not to query a big table, but just the needed one. If I'm making some mistakes ( as I did, because I studied SQL few years ago ), please tell me :)
Now I'm making changes about the INSERT and the UPDATE. Only these 2 "operations" would have the _SQLite_FastEscape() function, am I right?
Thanks for your time :) I rellay appreciate it :)
Have a wonderful day!
Francesco :D 


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

ALWAYS GOOD TO READ:

In case I am violating some pseudo Forum rule, or I am doing something wrong, I want let you know that I'm not doing this on purpose, and for this, I kindly ask you to send me a private message about the "bad content" I posted, in order to edit/remove it, and to not be warned wrongly.
Thanks in advance.

 

Share this post


Link to post
Share on other sites
jchd

For the costo field: also remove whitespaces.

Querying one "big" table is almost always preferable to have several identical tables. There are some reasons for that:

  • First, SQLite (and RDBMS in general) are very efficient at manipulating huge amounts of data. SQLite routinely manages multi-terabytes tables with billions rows, provided correct design of the schema.
  • Second, you don't have to write and manage separate code to access TableA, TableB, TableC, ... Add a discriminating column (e.g. "Brand") where you put 'Siemens', 'Rockwell', ...(*) and use a WHERE clause to specify which brand you're interessed in.
  • Third, it's better for efficiency of the caches.

(*) Better yet: set the column "Brand" to refer to a Brands table, using a foreign key.

You need to escape any text literal which may contain one or more single quote. This includes statements like:

select colA, colB, colC from mytable where colA like _SQLiteFastEscape($sometext) ...


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
FrancescoDiMuro

Hey @jchd!
You are a very nice person :)
No one here helped me so much, and, since you starded doing that, I'm learning a lot of things...
Now, I should change my code ( 1783 rows :frantics: ) about what you were saying...
I know I can do it :D
Quick question... I don't remember how FK works...
Could you explain me something about it or give to me ( I am not lazy looking for foreign key on Google, but maybe you have a more direct explanation that I could understand better than something on Google :) ) a reference :)
Thanks :D 

EDIT:

By the way, I don't know if I'll do this new table, because I can't manage one brand with barcodes...
If I add a new product, I do it by barcode... So, If the last brand has not a barcode, and atm, I can't generate it, I can't do what you suggested ( would be AMAZING! )... Do you have any idea? Or, for now, I could manage the db as I am doing, without creating a new table with all brands? Thanks :D 
 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

ALWAYS GOOD TO READ:

In case I am violating some pseudo Forum rule, or I am doing something wrong, I want let you know that I'm not doing this on purpose, and for this, I kindly ask you to send me a private message about the "bad content" I posted, in order to edit/remove it, and to not be warned wrongly.
Thanks in advance.

 

Share this post


Link to post
Share on other sites
jchd

A foreign key in SQL is a reference (via a unique identifier, often an integer) from a child table to a parent table. Foreign keys are widely used to avoid duplication of data (like in your case, to avoid repeating for every Siemens item that its brand is 'Siemens') and also to link together entities in different semantic spaces.

Duplicating data is problematic: not only that eats up storage and cache space pointlessly but also because it's a window wide open to DB inconsistancies. For instance, it too easy to misspell/mistype 'Siemens' as 'Seimens'.

Now imagine you have a stock of items (you seem to have that) which you sell. Let's skip a number of details. At some point you're going to have to process orders and produce detailled invoices. At this point, what do you think is more robust, more efficient and more compact?

Create invoices containing the full data of the client, the delivery point and all the items sold stated in full,
OR
Create invoices containing references to the client, the delivery point and sold items.

Obviously, the second paradigm is better. You achieve that by using, in the invoices table, foreign keys (= FK = reference) to the client entry in the client table, also FK to the delivery point in the corresponding table and also FK to item in the stock table for each sold item in the invoice.

For a complete documentation about FK under SQLite, turn to https://www.sqlite.org/foreignkeys.html


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
FrancescoDiMuro

Thanks for your explanation, @jchd.
But, how would I apply your example to my script? Should I create a table "Brand", and then?
Thanks for your help :) 


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

ALWAYS GOOD TO READ:

In case I am violating some pseudo Forum rule, or I am doing something wrong, I want let you know that I'm not doing this on purpose, and for this, I kindly ask you to send me a private message about the "bad content" I posted, in order to edit/remove it, and to not be warned wrongly.
Thanks in advance.

 

Share this post


Link to post
Share on other sites
jchd

Most probably yes. DB design obeys both rules ("normalizations", to apply reasonnably) and some white magic. Context & requirements & experience & common sense are the guides.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
Skysnake

Hi @FrancescoDiMuro, there are several good publications on SQL. I suggest you look for titles like

SQL Cookbook
Query Solutions and Techniques for Database Developers
By Anthony Molinaro

Using SQLite by  Jay A. Kreibic published by O'Reilly

Skysnake


Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I am building a management for the company I work with, and I just imported a real amount of rows ( about 29000 ), in my SQLite DB.
      The thing I am not understanding, is the time that the script takes to build this amount of rows in the ListView.
      I didn't measure it, but I think it took 2 minutes or so to create each ListView item...
      It is normal that it takes so much time?
      What can I do to improve the creation of the items?

      Here's the code I am using to query and to create ListView items...
      ; Articles ListView: Global $lvwArticles = GUICtrlCreateListView("ID|Fornitore|Codice|Descrizione|EU|Prezzo|Sconto Applicato|Note", 14, 87, 1507, 660, BitOR($GUI_SS_DEFAULT_LISTVIEW,$LVS_SORTASCENDING,$LVS_SORTDESCENDING), BitOR($WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT)) ; Query $strQuery = "SELECT * FROM ARTICOLI;" ; Query Execution _SQLite_GetTable2d($objDatabase, $strQuery, $arrResult, $intRows, $intColumns) If @error Then ; Error Handling Else ; Cleaning the ListView _GUICtrlListView_DeleteAllItems($lvwArticles) If @error Then ; Error Handling Else ; No records in the Table If UBound($arrResult) < 2 Then ; Error Handling Else _GUICtrlListView_BeginUpdate($lvwArticles) For $intCounter = 1 To UBound($arrResult) - 1 $strListViewItem = $arrResult[$intCounter][0] & "|" & _ $arrResult[$intCounter][1] & "|" & _ $arrResult[$intCounter][2] & "|" & _ $arrResult[$intCounter][3] & "|" & _ $arrResult[$intCounter][4] & "|" & _ $arrResult[$intCounter][5] & "|" & _ $arrResult[$intCounter][6] & "|" & _ $arrResult[$intCounter][7] $objListViewItem = GUICtrlCreateListViewItem($strListViewItem, $lvwArticles) Next _GUICtrlListView_EndUpdate($lvwArticles) EndIf EndIf EndIf Thanks in advance


      Best Regards.
    • dangr82
      By dangr82
       
      I have created this function for a database, but I can not make it work. I always have two error messages: "not an error" ... and the file created, in the script directory, does not contain anything.
      Global $sDBName = "Hen.db" Func DatabaseTable() Local $sConnDB _SQLite_Startup() If @error Then MsgBox($MB_SYSTEMMODAL, "SQLite Error", "SQLite.dll Can't be Loaded!") Exit -1 EndIf $sConnDB = _SQLite_Open($sDBName) If @error Then MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Can't Load Database!") Exit -1 EndIf If Not _SQLite_Exec($sDBName, 'CREATE TABLE Animal ("Name", "Age");') = $SQLITE_OK Then MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg()) If Not _SQLite_Exec($sDBName, 'INSERT INTO Animale VALUES ("Charlie","5");') = $SQLITE_OK Then MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg()) _SQLite_Close($sConnDB) _SQLite_Shutdown() EndFunc  
    • Eminence
      By Eminence
      Hello,
      I've been searching on how to select the first row in my database which includes a time column based on the latest start_time date for today's date.
      This is my current code:
      Local $iCurrentDate = _Now() Local $sqlHandle = _dbOpen($sDbPath) Local $aResult, $iRows, $iCols _SQLite_GetTable2d($sqlHandle, "SELECT start_time FROM " & $srawDb & " ORDER BY datetime(start_time) DESC LIMIT 1", $aResult, $iRows, $iCols) _ArrayDisplay($aResult) _dbClose($sDbpath) What it does is it gets the first row entry in the database however it does not select the latest start_time entry in the database, it always select the first row. I've tried changing DESC to ASC to see if that will do it but the issue still remains. Any thoughts on this? Thanks in advance.
       
      *EDIT
      The date format in the database is by MM/DD/YYYY HH:MM:SS.
    • Seminko
      By Seminko
      In my recent project I'm downloading a bunch of data, so I decided to store it in a SQLite database. NOTE: I'm using sqlite3_x64.dll
      Everything is working just fine but I'm struggling with getting the Median value. SQLite has an Average function but not a Median one.
      I googled but all of the provided solutions are way above my pay-grade. After some more searching I found 'extension-functions.c' on the SQLite site where Median is included. After almost an hour of struggling I was able to successfully compile it into a DLL.
      So I downloaded @jchd's SQLiteExtLoad.au3 as seen here:
      But I'm getting these errors:
      "Path\SQLiteExtLoad.au3"(21,40) : warning: $g_hDll_SQLite: possibly used before declaration. Local $RetVal = DllCall($g_hDll_SQLite, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ "Path\SQLiteExtLoad.au3"(21,40) : error: $g_hDll_SQLite: undeclared global variable. Local $RetVal = DllCall($g_hDll_SQLite, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ So I tried, copying the function to my file and changing the DLL variable ($g_hDll_SQLite) directly to the DLL location (C:\...\.. .dll), but now this error fires
      If __SQLite_hChk($hConn, 1) Then Return SetError(@error, 0, $SQLITE_MISUSE) To be honest, I don't know what to use as the $hConn - handle of connection.
      I would appreciate any help, be it getting the median using SQLite queries or getting the DLL extension loaded using AutoIt.
      Thanks, S.
       
      EDIT: well, I suspect the $hConn variable refers to the return value of the _SQLite_Open function. Well, at least now _SQLite_EnableExtensions doesn't give errors. Now I run into problems with _SQLite_LoadExtension, which gives error -1, and extended 1. Apparently the 1 constant is a generic error where other error do not apply.
      BTW, anybody knows whether I need to compile the extension DLL "into" x64 when I use a x64 SQLite? That might be the problem...
       
      EDIT2: I recompiled the dll and tried it using the SQLite3.exe and it works, so I'm confident the extension DLL has been created correctly

    • AdamUL
      By AdamUL
      I have been testing AutoIt 3.3.14.3 with SQLite, and the Help File examples.  The examples that I have tested are throwing errors or not doing anything.  I have sqlite3.dll, sqlite3_x64.dll, and sqlite3.exe in the directories with the testing script.  I am copying the examples directly from the help file into a test script for testing with no edits.  The _SQLite_GetTable2d example is returning an error ("Library used incorrectly") with each _SQLite_Exec command.  The _SQLite_FastEncode example returns an empty dialog box.  The _SQLite_Exec example only prints out the SQLite version, and nothing else in the SciTE console.  Currently, I'm still searching for what is causing this issue.  I'm on Windows 7 Enterprise 64-bit.  Is anyone else having this issue?  
       
      Adam
       
×