prepared statement

  1. 4 years ago

    Hello,
    Can anyone tell me what is wrong here. I am getting a Syntax error with the prepared statement

      
    
      Dim db As New SQLiteDatabase
       Dim ps As SQLitePreparedStatement
      
      db.DatabaseFile = mod_SQLite.mod_Schema_Control.UTIL_GET_DB_File_Location
      
      If db.Connect Then
        ' Prepare the Statement
        //ps = SQLitePreparedStatement(db.Prepare(SET_Employee))
        
        ps = SQLitePreparedStatement(db.Prepare(("INSERT INTO Credentials (Company_Name, Database_Server, Database_Name, User_iD, Password) Values (?, ?, ?, ?, ?)"))
        
        'Bind the parameters
        ps.BindType(0, SQLitePreparedStatement.SQLITE_TEXT)
        ps.BindType(1, SQLitePreparedStatement.SQLITE_TEXT)
        ps.BindType(2, SQLitePreparedStatement.SQLITE_TEXT)
        ps.BindType(3, SQLitePreparedStatement.SQLITE_TEXT)
        ps.BindType(4, SQLitePreparedStatement.SQLITE_TEXT)
        
        ps.Bind(0, CustomerName)
        ps.Bind(1,DatabaseServer)
        ps.Bind(2, DatabaseName)
        ps.Bind(3, userid)
        ps.Bind(4, password)
        
        ps.SQLExecute
        
        If db.Error Then MsgBox Str(db.ErrorCode) + " - " + db.ErrorMessage
        
        db.Close
      Else
        // Couldn't Connect to the Database
        MsgBox Str(db.ErrorCode) + " - " + db.ErrorMessage
      End If
      
    

    Thanks alll.. I am having this issue as well..

    Not sure of the string to use here

    ps = SQLitePreparedStatement(db.Prepare("UPDATE Credentials SET Company_Name = ?, Database_Server = ?, Database_Name = ?, User_id = ?, password = ? WHERE id = ?")

    Any ideas why its not working

  2. Albin K

    2 May 2014 Europe (Sweden)

    Think it should be:

    ps = SQLitePreparedStatement(db.Prepare("INSERT INTO Credentials (Company_Name, Database_Server, Database_Name, User_iD, Password) Values (?, ?, ?, ?, ?)")
  3. Greg O

    2 May 2014 Xojo Inc Somewhere near Raleigh, NC

    You are missing a parenthesis at the end (or there are too many right after db.prepare).

    Also, you don't need to cast the prepared statement:

    ps = db.Prepare("INSERT INTO Credentials (Company_Name, Database_Server, Database_Name, User_iD, Password) Values (?, ?, ?, ?, ?)")

    That should work.

  4. Kem T

    2 May 2014 Pre-Release Testers, Xojo Pro, XDC Speakers New York

    You can even go the other way and Dim ps As PreparedSQLStatement, the super class for all prepared statements. If you decide to switch to a different database engine, this won't have to change (although you'd still have to change or remove the BindType statements).

  5. Thanks alll.. I am having this issue as well..

    Not sure of the string to use here

    ps = SQLitePreparedStatement(db.Prepare("UPDATE Credentials SET Company_Name = ?, Database_Server = ?, Database_Name = ?, User_id = ?, password = ? WHERE id = ?")

    Any ideas why its not working

  6. Sorry for haste. I found it . no closing )

    Thanks

    Chris

  7. last week

    Richard D

    Jun 12 Pre-Release Testers Europe (UK, London)

    @Chris T Thanks alll.. I am having this issue as well..

    Not sure of the string to use here

    ps = SQLitePreparedStatement(db.Prepare("UPDATE Credentials SET Company_Name = ?, Database_Server = ?, Database_Name = ?, User_id = ?, password = ? WHERE id = ?")

    Any ideas why its not working

    I would define a lstr which the string for the UPDATE and then use the lstr in the db.prepare

or Sign Up to reply!