Jump to content

Recommended Posts

Posted

hi guys 

i try to insert into db  sqlite a 2 variable , my db is:

|id|name|xml_code|

1 questions? sqlite can set autoincrement a id ???

2 questions ?

this syntax is correct???

_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\eBay\eBay.db")
    If @error Then
    MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Can't create a memory Database!")
    ;Exit -1
    EndIf

    _SQLite_Exec(-1,"INSERT INTO eBayNewItem (titolo,xml_code) VALUES ("&$titolo&","&$_XML_item_insert&");")
    If @error Then
    MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Can't insert in  Database!")
    ;Exit -1
    EndIf
    _SQLite_Close()
    _SQLite_Shutdown()

i have  return error can't insert in Database!

 

Posted

Hello. Check the error message _SQLite_ErrMsg().

 

Also make sure you've created your id field INTEGER PRIMARY KEY AUTOINCREMENT.

 

Saludos

Posted (edited)

In most SQLite uses, the AUTOINCREMENT qualifier is superfluous and in general doesn't mean what people think it means. Declaring an explicit rowid as Id INTEGER PRIMARY KEY  is good enough for most uses. Making it not nul is also good due to historic reasons.

Note that your DB is not memory-based, contrary to the error message shown. Also if the DB is new, you need to explicitely create a table to hold your data.

In SQL, literal text has to be enclosed into single quotes. Then if the text variables you're inserting themselves contain one or more single quote, the statement will fail. A good precaution is to always protect against text containing single quotes by escaping (doubling) them.

Albeit SQLite is flexible enough to let you store any datatype in any column regardless of that column's declaration, I recommend you explicitely declare the column along with their expected datatype.

Your code might then be (untested):

_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\eBay\eBay.db")
If @error Then
    MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Can't create a disk Database!")
    Exit -1
EndIf

_SQLite_Exec(-1,"create table if not exists eBayNewItem (id integer not nul primary key, titolo text, xml_code text)")

_SQLite_Exec(-1,"INSERT INTO eBayNewItem (titolo, xml_code) " & _
                    "VALUES (" & _SQLite_FastEscape($titolo) & "," & _SQLite_FastEscape($_XML_item_insert) & ");")
If @error Then
    MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Can't insert in Database!")
    Exit -1
EndIf
_SQLite_Close()
_SQLite_Shutdown()

 

Edited by jchd
typo

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)

Posted

the  table is  created ofcourse  not null integer primiry key , and used  your  code

_SQLite_Exec(-1,"INSERT INTO eBayNewItem (titolo, xml_code) " & _
                    "VALUES (" & _SQLite_FastEscape($titolo) & "," & _SQLite_FastEscape($_XML_item_insert) & ");")
If @error Then
    MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Can't insert in Database!")
    Exit -1
EndIf

but nothing  return the same error can't insert in database ??

is possible have some details of error???

thankz

 

Posted

Why not displaying SQLite error message instead of yours?

If @error Then
    MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg (-1))
    Exit -1
EndIf

It should be more informative.

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)

Posted

Do you mean it now works flawlessly?

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)

Posted

yes i  did do only this  two modify  add a new columns at structure of the table  and  insert  your code for debug

 

now  my table is

|id|titolo|xml_code|Item_spec|

the code is this

_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\eBay\eBay.db")
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Can't create a memory Database!")
        ;Exit -1
    EndIf
    _SQLite_Exec(-1, "INSERT INTO eBayNewItem (titolo, xml_code) " & _
            "VALUES (" & _SQLite_FastEscape($titolo) & "," & _SQLite_FastEscape($_XML_item_insert) &") ;")
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg(-1))
        ;Exit -1
    EndIf
    _SQLite_Close()
    _SQLite_Shutdown()

now  work  but if i try to insert  a new  columns like this

_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\eBay\eBay.db")
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Can't create a memory Database!")
        ;Exit -1
    EndIf
    _SQLite_Exec(-1, "INSERT INTO eBayNewItem (titolo, xml_code,item_spec) " & _
            "VALUES (" & _SQLite_FastEscape($titolo) & "," & _SQLite_FastEscape($_XML_item_insert) &",Multi Variation) ;")
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg(-1))
        ;Exit -1
    EndIf
    _SQLite_Close()
    _SQLite_Shutdown()

i have  this error

sqlite near Varation syntax error

 

Posted (edited)

set quotes to this part too 'Multi Variation'

 

Saludos

Edited by Danyfirex
Posted

... that or better _SQLite_FastEscape() the variable.

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)

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
  • Recently Browsing   0 members

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