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.
telefunkenAsked:
Who is Participating?
 
Gustav BrockConnect With a Mentor CIOCommented:
Try with:

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";

/gustav
0
 
telefunkenAuthor Commented:
This is pesky syntax, platform to platform, so appreciate the VERY QUICK and ON TARGET response!
0
 
Gustav BrockCIOCommented:
Thanks!

/gustav
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.