Sign in to follow this  
Followers 0
wjans

syntax error in _sqlite_exec

5 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

@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

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

@Martin, adding the type solved the problem :) Thanks.

Share this post


Link to post
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
Sign in to follow this  
Followers 0