Jump to content

Sqlite3 insert problem


faustf
 Share

Recommended Posts

hi guys  i have  a little problem when insert a  txt  inside a db sqlite3

i create a script like this

Local $sTextInserted = _True_ReadFile(@ScriptDir & "\WEB-SITE\Depop\INSERIMENTI\insert_prod.txt", 0)
        _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")
            ; Exit -1
        EndIf
        Local $DB = _SQLite_Open(@ScriptDir & "\WEB-SITE\Depop\Depop.db")
        If @error Then
            MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Can't create a memory Database!")
            ;Exit -1
        EndIf
        _SQLite_Exec(-1, "INSERT INTO DepopHistory (Descrizione, txt_insert,) " & _
                "VALUES (" & _SQLite_FastEscape($sLDescrizione) & "," & _SQLite_FastEscape($sTextInserted) & ");")
        If @error Then
            MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg(-1))
            ;Exit -1
        EndIf
        _SQLite_Close()
        _SQLite_Shutdown()
        
        
        ; #INDEX# ========================================================================
; Title .........: GUI_Configure.au3
; AutoIt Version : 3.3.14.2++
; Language ......: Italian
; Description ...: A collection of Function for Logic of Gest
; Author ........: Faustf
; What do you do.: Reaad data in File
; Version .......: 0.0.1 BETA - Work in progress 15/03/2016
; Syntax ........: file path + attribute like this $FO_READ
; ================================================================================

Func _True_ReadFile($sFilePath, $attribute)
    Local $hFileOpen = FileOpen($sFilePath, $attribute)
    If $hFileOpen = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")
        Return False
    EndIf
    Local $sFileRead = FileRead($hFileOpen)
    Return $sFileRead

    FileClose($hFileOpen)
EndFunc   ;==>_True_ReadFile

the  text is  this

_____________
www.xxxxx.com/sito2/eBay/FOTO/1/IMG1475828624406 - Copy - Copy.jpg
www.axxxxxi.com/sito2/eBay/FOTO/1/IMG1475828624406 - Copy.jpg
www.xxxxxx.com/sito2/eBay/FOTO/1/IMG1475828624406.jpg
_____________
djfdj
_____________
#gel#uv
_____________
dalla cinta in su
_____________
Corriere
_____________
12.00
_____________
12.00
_____________
50.00
_____________

 return always  this error

!   SQLite.au3 Error
--> Function: _SQLite_Exec
--> Query:    INSERT INTO DepopHistory (Descrizione, txt_insert,) VALUES ('wafsafasfa','_____________
www.xxxxxxxxx.com/sito2/eBay/FOTO/1/IMG1475828624406 - Copy - Copy.jpg
www.xxxxxxxxx.com/sito2/eBay/FOTO/1/IMG1475828624406 - Copy.jpg
www.xxxxxxxxxx.com/sito2/eBay/FOTO/1/IMG1475828624406.jpg
_____________
wafsafasfa
_____________
#gel#uv
_____________
intimo
_____________
Corriere
_____________
232
_____________
12.00
_____________
50.00
_____________
');
--> Error:    near ")": syntax error

some can help me???  thnakzzz at all again  :)

 

Link to comment
Share on other sites

Hi @faustf

I think you should try binding values to statements.

Here's an example from autoit-script.ru

#include <SQLite.au3>

Local $s_FileDB = @ScriptDir & '\Test.db', $h_DB, $a_Data[10001][2] = [[10000]], $i_Timer, $aRes, $iRows, $iColumns
Local $hQuery = null

For $i = 1 To $a_Data[0][0]
    $a_Data[$i][0] = $i
    $a_Data[$i][1] = Hex($i, 8)
Next

_SQLite_Startup()
If @error Then Exit 1

$h_DB = _SQLite_Open($s_FileDB)
If @error Then Exit 2

_SQLite_Exec($h_DB, 'DROP TABLE IF EXISTS TEST_TABLE;CREATE TABLE TEST_TABLE ([NUM_INT] INTEGER, [NUM_HEX] TEXT);')

$i_Timer = TimerInit()
_SQLite_Exec($h_DB, 'BEGIN TRANSACTION;')

_SQLite_Query($h_DB, 'INSERT INTO TEST_TABLE VALUES (?, ?);',$hQuery) ;Компонуем шаблон запроса
For $i = 1 To $a_Data[0][0]
    _SQLite_BindText($hQuery, 1, $a_Data[$i][0]) ;Вставляем данные в скомпонованный шаблон
    _SQLite_BindText($hQuery, 2, $a_Data[$i][1]) ;Вставляем данные в скомпонованный шаблон
    _SQLite_Step($hQuery)           ;Выполняем запрос
    _SQLite_ClearBindings($hQuery)  ;Подчищаемся
    _SQLite_QueryReset($hQuery)     ;Подчищаемся
Next

_SQLite_QueryFinalize($hQuery)
_SQLite_Exec($h_DB, 'END TRANSACTION;')

ConsoleWrite('Insert time: ' & TimerDiff($i_Timer) & ' msec' & @LF)

If _SQLite_GetTable2d($h_DB, 'SELECT * FROM TEST_TABLE;', $aRes, $iRows, $iColumns) Then
    ConsoleWrite('ERROR' & @LF)
Else
    ConsoleWrite('$iRows: ' & $iRows & @LF)
    ConsoleWrite('$iColumns: ' & $iColumns & @LF)
    _ArrayDisplay($aRes, 'TEST_TABLE')
EndIf

_SQLite_Close($h_DB)
_SQLite_Shutdown()

Func _SQLite_BindText($hQuery, $iRowID, $sTextRow)
    Local $iRval = DllCall($__g_hDll_SQLite, "int:cdecl", "sqlite3_bind_text16", _
            "ptr", $hQuery, _
            "int", $iRowID, _
            "wstr", $sTextRow, _
            "int", -1, _
            "ptr", NULL)
    If @error Then Return SetError(1, @error, $SQLITE_MISUSE) ; DllCall error
    If $iRval[0] <> $SQLITE_OK Then
        Return SetError(-1, 0, $iRval[0])
    EndIf
    Return $iRval[0]
EndFunc

Func _SQLite_ClearBindings($hQuery)
    Local $avRval = DllCall($__g_hDll_SQLite, "int:cdecl", "sqlite3_clear_bindings", "ptr", $hQuery)

    If @error Then Return SetError(1, @error, $SQLITE_MISUSE) ; DllCall error
    If $avRval[0] <> $SQLITE_OK Then SetError(-1)
    Return $avRval[0]
EndFunc

Func _SQLite_Step($hQuery)
    Local $iRval_Step = DllCall($__g_hDll_SQLite, "int:cdecl", "sqlite3_step", "ptr", $hQuery)
    If @error Then Return SetError(1, @error, $SQLITE_MISUSE) ; DllCall error
    Return $iRval_Step[0]
EndFunc

 

Link to comment
Share on other sites

  • Developers

Wild guess:

_SQLite_Exec(-1, "INSERT INTO DepopHistory (Descrizione, txt_insert) " & _
                "VALUES (" & _SQLite_FastEscape($sLDescrizione) & ",'hello boys');")

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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