Jump to content

sqlite sintax insert problem


Recommended Posts

hi guy

 i have program  it  must  insert in db  a simple 8 item  name  mail etc etc

i  do a script  like  this

Func _inserisci_anagrafica()
    $nome_ana = GUICtrlRead($input9)
    $mail_ana = GUICtrlRead($Input10)
    $tele_ana = GUICtrlRead($Input11)
    $comune_ana = GUICtrlRead($Input12)
    $indi_ana = GUICtrlRead($Input14)
    $passw_ana = GUICtrlRead($Input13)
    $paypal_ana = GUICtrlRead($Input15)

    SQLITE_APERTURA() ;  con questa  funzione  facciopartire sql e  apro il db robo_annunci nella script dir

    If Not _SQLite_Exec(-1, "INSERT INTO configurazione(nome,email,telefono,comune,indirizzo,password,paypal) VALUES ('" & $nome_ana & "','" & $mail_ana & "''" & $tele_ana & "','" & $comune_ana & "''" & $indi_ana & "','" & $passw_ana & "''" & $paypal_ana & "');") = $SQLITE_OK Then _
            MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg())

    SQLITE_CHIUSURA() ;  con questa  funzione  chiudo il database e shutdown lsqlite

EndFunc   ;==>_inserisci_anagrafica

but  it give  me  this  error

 Query:    INSERT INTO configurazione(nome,email,telefono,comune,indirizzo,password,paypal) VALUES ('Input9','Input10''Input11','Input12''Input14','Input13''Input15');
--> Error:    4 values for 7 columns


some one   could  help me  :D thankz

at all

Link to comment
Share on other sites

faustf,

You're missing three commas between values. Note that your statement would also fail if ever a single quote is part of one of the string entered in the GUI.

This should work better:

Func _inserisci_anagrafica()
    $nome_ana = GUICtrlRead($input9)
    $mail_ana = GUICtrlRead($Input10)
    $tele_ana = GUICtrlRead($Input11)
    $comune_ana = GUICtrlRead($Input12)
    $indi_ana = GUICtrlRead($Input14)
    $passw_ana = GUICtrlRead($Input13)
    $paypal_ana = GUICtrlRead($Input15)

    SQLITE_APERTURA() ;  con questa  funzione  facciopartire sql e  apro il db robo_annunci nella script dir

;~  If Not _SQLite_Exec(-1, "INSERT INTO configurazione(nome,email,telefono,comune,indirizzo,password,paypal) VALUES ('" & $nome_ana & "','" & $mail_ana & "','" & $tele_ana & "','" & $comune_ana & "','" & $indi_ana & "','" & $passw_ana & "','" & $paypal_ana & "');") = $SQLITE_OK Then _
;~          MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg())
; ======= prefer this
    If Not _SQLite_Exec(-1, "INSERT INTO configurazione (" & _
                                "nome," & _
                                "email," & _
                                "telefono," & _
                                "comune," & _
                                "indirizzo," & _
                                "password," & _
                                "paypal) " & _
                            "VALUES (" & _
                                _SQLite_FastEscape($nome_ana) & "," & _
                                _SQLite_FastEscape($mail_ana) & "," & _ 
                                _SQLite_FastEscape($tele_ana) & "," & _
                                _SQLite_FastEscape($comune_ana) & "," & _
                                _SQLite_FastEscape($indi_ana) & "," & _
                                _SQLite_FastEscape($passw_ana) & "," & _
                                _SQLite_FastEscape($paypal_ana) & _
                            ");") = $SQLITE_OK Then _
        MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg())

    SQLITE_CHIUSURA() ;  con questa  funzione  chiudo il database e shutdown lsqlite

EndFunc   ;==>_inserisci_anagrafica

There is no need to open and close the DB at every statement. Typically code should be like that:

...

_SQLite_Startup()
Local $hDB

$hDB = _SQLite_Open($sDbName)

... all of DB operations spread in various functions

_SQLite_Close($hDB)
_SQLite_Shutdown()

One last thing: writing  If Not _SQlite_Exec( ... ) = _$SQLITE_OK should be:  If _SQlite_Exec( ... ) <> _$SQLITE_OK

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)

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...