Link to home
Start Free TrialLog in
Avatar of telefunken
telefunken

asked on

ADBC SQL INSERT AND UPDATE

Does anyone have examples of working ADBC SQL INSERT and UPDATE statements?  I can't get any of the syntax to work. I'm guessing the problem is with single vs double quotes and setting values.


// Globals
var dbName = "TestDB";
var dbConn = null;
var stmtObj = null;
var test1 = "TEST";
var test2 = "TestBad";

//this is the easy part that works:
var sqlToExecute = "Select * from Customers";

//this is with outside single quotes
var sqlToExecute2 = 'INSERT INTO "Customers" ("CustomerID", "FullName", "NumGoodParts", "NumReject", "RejectCode") VALUES ( 7, test1, 9, 1, test2)';

var sqlToExecute3 = 'UPDATE "Customers" Set "FullName" = test1, "NumGoodParts" = 9, "NumReject" = 1; "RejectCode" = test2 WHERE "CustomerID" = 6';

//this is with outside double quotes
var sqlToExecute2 = "INSERT INTO Customers (CustomerID, FullName, NumGoodParts, NumReject, RejectCode) VALUES ( 7, test1, 9, 1, test2)";

var sqlToExecute3 = "UPDATE Customers Set FullName = test1, NumGoodParts = 9, NumReject = 1; RejectCode = test2 WHERE CustomerID = 6';

function save()
{
  try
  {
    //first connect to the database
    app.alert("Attempting Connection...");
    dbConn = ADBC.newConnection(dbName);
    if(dbConn == null)
       throw "Error connecting";

    stmtObj = dbConn.newStatement();

    // Execute the SQL statement inside the database
    stmtObj.execute(sqlToExecute2);

  }
  catch(exc)
  {
    console.println(exc);
    throw "Unable to Connect to Database";
  }

}

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of telefunken
telefunken

ASKER

This is pesky syntax, platform to platform, so appreciate the VERY QUICK and ON TARGET response!
Thanks!

/gustav