Jump to content

Sqlite3 Select questions


faustf
 Share

Recommended Posts

hi guys , i have a little problem with a select in sqlite 3  , in pratical  if  i run this 

Local $aLResult = _Sqlite3_Read(@ScriptDir & "\MaoDb.db", "SELECT * FROM Anagrafica_Arnie WHERE id = 1;")

work good and return a row 1

but if i run  this

$sLNomeArnia= A

Local $aLResult = _Sqlite3_Read(@ScriptDir & "\MaoDb.db", "SELECT * FROM Anagrafica_Arnie WHERE Arnia_Name = " & $sLNomeArnia & ";")

no such column A

but why ???

Func _Sqlite3_Read($sDB, $query_read)

    Local $hQuery, $sMsg, $aRow, $aResult, $iRows, $iColumns

    _SQLite_Startup()
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "SQLite Error", "SQLite3.dll Can't be Loaded!" & @CRLF & @CRLF & _
                "Not FOUND in @SystemDir, @WindowsDir, @ScriptDir, @WorkingDir, @LocalAppDataDir\AutoIt v3\SQLite")
    EndIf
    Local $DB = _SQLite_Open($sDB) ;@ScriptDir & "\WEB-SITE\eBay\eBay.db"
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Can't create a memory Database!")
    EndIf
    $iRval = _SQLite_GetTable(-1, $query_read, $aResult, $iRows, $iColumns)
    If $iRval = $SQLITE_OK Then
        Return $aResult
    Else
        MsgBox($MB_SYSTEMMODAL, "SQLite Error: " & $iRval, _SQLite_ErrMsg())
    EndIf

    _SQLite_Close()
    _SQLite_Shutdown()
EndFunc   ;==>_Sqlite3_Read

thankz at all

Link to comment
Share on other sites

hi guys , i have a little problem with a select in sqlite 3  , in pratical  if  i run this 

Local $aLResult = _Sqlite3_Read(@ScriptDir & "\MaoDb.db", "SELECT * FROM Anagrafica_Arnie WHERE id = 1;")

work good and return a row 1

but if i run  this

$sLNomeArnia= A

Local $aLResult = _Sqlite3_Read(@ScriptDir & "\MaoDb.db", "SELECT * FROM Anagrafica_Arnie WHERE Arnia_Name = " & $sLNomeArnia & ";")

no such column A

but why ???

Func _Sqlite3_Read($sDB, $query_read)

    Local $hQuery, $sMsg, $aRow, $aResult, $iRows, $iColumns

    _SQLite_Startup()
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "SQLite Error", "SQLite3.dll Can't be Loaded!" & @CRLF & @CRLF & _
                "Not FOUND in @SystemDir, @WindowsDir, @ScriptDir, @WorkingDir, @LocalAppDataDir\AutoIt v3\SQLite")
    EndIf
    Local $DB = _SQLite_Open($sDB) ;@ScriptDir & "\WEB-SITE\eBay\eBay.db"
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Can't create a memory Database!")
    EndIf
    $iRval = _SQLite_GetTable(-1, $query_read, $aResult, $iRows, $iColumns)
    If $iRval = $SQLITE_OK Then
        Return $aResult
    Else
        MsgBox($MB_SYSTEMMODAL, "SQLite Error: " & $iRval, _SQLite_ErrMsg())
    EndIf

    _SQLite_Close()
    _SQLite_Shutdown()
EndFunc   ;==>_Sqlite3_Read

thankz at all

Link to comment
Share on other sites

the field "Arnia_Name" seems to be a string, so you have to add quotes :

Local $aLResult = _Sqlite3_Read(@ScriptDir & "\MaoDb.db", "SELECT * FROM Anagrafica_Arnie WHERE Arnia_Name = '" & $sLNomeArnia & "';")

Also, look at _SQLite_FastEscape

Link to comment
Share on other sites

@Earthshine is perfectly right.

Always retrieve the only columns you need and if you do require them all, then list them explicitely in the order that best fits processing in your programming language.
Why?
Simply because if ever you need to reorder, add or remove some column(s) in a table, then all your applications using this table will need rewrite, testing, release, along with a way to cope with old and new designs (think upgrade and backups).

Also, double quotes are used in SQL for schema names (databases, tables, views, indices, columns, aliases), while single quotes are used to enclose string values.

 

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)

Link to comment
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
 Share

  • Recently Browsing   0 members

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