Subject Unknown token CREATE
Author edcurren
Hello all,

While attempting to execute the SQL (below) in code I receive an
error message of

Invalid token
Dynamic SQL Error
SQL error code = -104
Token unknown - line 10, char 1
CREATE

When I run the following command line I have no problems at all:
isql 'C:\SourceCode\Projects\Database\testdb.fdb' -i testsql.txt -
u 'SYSDBA' -p 'masterkey'.

Both are running the following SQL Code:
CREATE TABLE ApplicationState
(
Id CHAR (37) NOT NULL,
SystemVariable VARCHAR (50),
SystemValue VARCHAR (1024),

CONSTRAINT PK_APPLICATION_STATE PRIMARY KEY (Id)
);

CREATE TABLE LocalMachineAttributes
(
Id CHAR (37) NOT NULL,
AttributeName VARCHAR(10),
AttributeValue VARCHAR(20),

CONSTRAINT PK_LOCAL_MACHINE_CPUS PRIMARY KEY (Id)
);

The API code that is running the SQL code is below. I have been
using this code without problems, (although for SELECT / EXECUTE
PROCEDURE sql mostly).
int CDatabase::ExecuteNonQuery(string sqlToExecute, string
&ErrorMessage)
{
isc_stmt_handle stmt = NULL; /*
statement handle */
isc_db_handle DB = NULL; /* database
handle */
isc_tr_handle trans = NULL; /*
transaction handle */
ISC_STATUS_ARRAY status; /* status
vector */
ISC_STATUS *pStatus = status;
char nwldb[128];
bool errorFlag = false;
bool dbOpenFlag = false;

const char username[7] = { 0x53, 0x59, 0x53, 0x44, 0x42,
0x41, 0x00 }; //"SYSDBA";
const char password[10] = { 0x6D, 0x61, 0x73, 0x74, 0x65,
0x72, 0x6B, 0x65, 0x79, 0x00 }; //"masterkey";

char dpb_buffer[256], *dpb;
short dpb_length;

//sprintf(nwldb, "%s\\nwcldbf.nds", GetDatabaseDirectory
().c_str());
sprintf
(nwldb, "C:\\SourceCode\\Projects\\WatchDog\\Client\\Database\\nwcldbf
.nds");

dpb = dpb_buffer;
*dpb++ = isc_dpb_version1;
*dpb++ = isc_dpb_num_buffers;
*dpb++ = 1;
*dpb++ = 90;

// Set the db user name
*dpb++ = isc_dpb_user_name;
*dpb++ = strlen(username);
strcpy(dpb, username);
dpb += strlen(username);

// set the db password
*dpb++ = isc_dpb_password;
*dpb++ = strlen(password);
strcpy(dpb, password);
dpb += strlen(password);

/* *dpb++ = isc_dpb_encrypt_key;
*dpb++ = strlen(DatabaseEncryptionKey);
strcpy(dpb, DatabaseEncryptionKey);
dpb += strlen(DatabaseEncryptionKey);*/
//Encryption isn't supported yet

dpb_length = dpb - dpb_buffer;

if (isc_attach_database(status, 0, nwldb, &DB, dpb_length,
dpb_buffer))
{
if (status[0] == 1 && status[1])
{

char msg[512];
isc_sql_interprete(isc_sqlcode(status), msg,
512);
ErrorMessage += msg;
ErrorMessage += "\n";
while( isc_interprete(msg, &pStatus) )
{
ErrorMessage += msg;
ErrorMessage += "\n";
}
errorFlag = true;
}
}
else
{
dbOpenFlag = true;
}

if( !errorFlag )
{
if (isc_start_transaction(status, &trans, 1, &DB, 0,
NULL))
{
if (status[0] == 1 && status[1])
{
char msg[512];
isc_sql_interprete(isc_sqlcode
(status), msg, 512);
ErrorMessage += msg;
ErrorMessage += "\n";
while( isc_interprete(msg, &pStatus) )
{
ErrorMessage += msg;
ErrorMessage += "\n";
}
errorFlag = true;
}
}
}

/* Allocate a statement. */

if( !errorFlag )
{
if (isc_dsql_allocate_statement(status, &DB, &stmt))
{
if (status[0] == 1 && status[1])
{
char msg[512];
isc_sql_interprete(isc_sqlcode
(status), msg, 512);
ErrorMessage += msg;
ErrorMessage += "\n";
while( isc_interprete(msg, &pStatus) )
{
ErrorMessage += msg;
ErrorMessage += "\n";
}
errorFlag = true;
}
}
}

/* Prepare the statement. */
if( !errorFlag )
{
if (isc_dsql_prepare(status, &trans, &stmt, 0, (char
*)sqlToExecute.c_str(), 1, NULL))
{
if (status[0] == 1 && status[1])
{

char msg[512];
isc_sql_interprete(isc_sqlcode
(status), msg, 512);
ErrorMessage += msg;
ErrorMessage += "\n";
while( isc_interprete(msg, &pStatus) )
{
ErrorMessage += msg;
ErrorMessage += "\n";
}
errorFlag = true;
}
}
}

/* Execute the statement. */
if( !errorFlag )
{
if (isc_dsql_execute(status, &trans, &stmt, 1, NULL))
{
if (status[0] == 1 && status[1])
{

char msg[512];
isc_sql_interprete(isc_sqlcode
(status), msg, 512);
ErrorMessage += msg;
ErrorMessage += "\n";
while( isc_interprete(msg, &pStatus) )
{
ErrorMessage += msg;
ErrorMessage += "\n";
}
errorFlag = true;
}
}
}

/* Free statement handle. */
if( !errorFlag )
{
if (isc_dsql_free_statement(status, &stmt, NULL))
{
if (status[0] == 1 && status[1])
{

char msg[512];
isc_sql_interprete(isc_sqlcode
(status), msg, 512);
ErrorMessage += msg;
ErrorMessage += "\n";
while( isc_interprete(msg, &pStatus) )
{
ErrorMessage += msg;
ErrorMessage += "\n";
}
errorFlag = true;
}
}
}

if( !errorFlag )
{
if (isc_commit_transaction(status, &trans))
{
if (status[0] == 1 && status[1])
{

char msg[512];
isc_sql_interprete(isc_sqlcode
(status), msg, 512);
ErrorMessage += msg;
ErrorMessage += "\n";
while( isc_interprete(msg, &pStatus) )
{
ErrorMessage += msg;
ErrorMessage += "\n";
}
errorFlag = true;
}
}
}

if( !errorFlag || dbOpenFlag )
{
if (isc_detach_database(status, &DB))
{
if (status[0] == 1 && status[1] && !errorFlag)
{

char msg[512];
isc_sql_interprete(isc_sqlcode
(status), msg, 512);
ErrorMessage += msg;
ErrorMessage += "\n";
while( isc_interprete(msg, &pStatus) )
{
ErrorMessage += msg;
ErrorMessage += "\n";
}
}
}
}

return 0;
}

Again thanks to all for your kind help.
Ed