Jump to content

syntax error in _sqlite_exec


wjans
 Share

Recommended Posts

When trying to execute the following function with a variable as column name I get

! SQLite.au3 Error

--> Function: _SQLite_Exec

--> Query: ALTER TABLE MedSERVEUsers ADD COLUMN 20080901

--> Error: near "20080901": syntax error

When I add this without the variable it works fine. I tried all sorts of ", ' and ; but to no avail.

Func Add_Column($colName)
    
    If Not _SQLite_Exec($hDB, "ALTER TABLE MedSERVEUsers ADD COLUMN " & $colName) = $SQLITE_OK Then
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg())
    EndIf
    MsgBox(1, "Add Column", "column " & $colName & " has been added")
    
EndFunc   ;==>Add_Column
Link to comment
Share on other sites

@wjans

Perhaps this should work

#include <SQLite.au3>

Func Add_Column($colName)
    Local $hDB

    If Not _SQLite_Exec($hDB, "ALTER TABLE MedSERVEUsers ADD COLUMN " & $colName) = $SQLITE_OK Then
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg())
    EndIf
    MsgBox(64 , "Add Column", "Column " & $colName & " has been added")
EndFunc   ;==>Add_Column
Edited by FireFox
Link to comment
Share on other sites

When trying to execute the following function with a variable as column name I get

! SQLite.au3 Error

--> Function: _SQLite_Exec

--> Query: ALTER TABLE MedSERVEUsers ADD COLUMN 20080901

--> Error: near "20080901": syntax error

When I add this without the variable it works fine. I tried all sorts of ", ' and ; but to no avail.

Func Add_Column($colName)
    
    If Not _SQLite_Exec($hDB, "ALTER TABLE MedSERVEUsers ADD COLUMN " & $colName) = $SQLITE_OK Then
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg())
    EndIf
    MsgBox(1, "Add Column", "column " & $colName & " has been added")
    
EndFunc   ;==>Add_Column
Using this to test, it looks like you have to enclose a number in quotes, so maybe this would work

If Not _SQLite_E xec($hDB, 'ALTER TABLE MedSERVEUsers ADD COLUMN "' & $colName & '" INTEGER') = $SQLITE_OK Then

Assumiung thecolumn is for integers.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Thanks for the reply.

I didn't post the complete script, but opening the DB and executing SQL statements work OK, as long as I don't use a variable ...

@wjans

Perhaps this should work

#include <SQLite.au3>

Func Add_Column($colName)
    Local $hDB

    If Not _SQLite_Exec($hDB, "ALTER TABLE MedSERVEUsers ADD COLUMN " & $colName) = $SQLITE_OK Then
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg())
    EndIf
    MsgBox(64 , "Add Column", "Column " & $colName & " has been added")
EndFunc   ;==>Add_Column
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...