cancel
Showing results for 
Search instead for 
Did you mean: 

strange problem with SQLDBC

Former Member
0 Kudos

I had written a small program to create a table in MaxDB using SQLDBC_C and C (In fact it was just a modification of the Helloworld.cpp sample program)

I had tested that program and it was working fine.

When i run the same program today it's not working. I know that sounds very strange. But that's how it is.

Also the SQLDBC_Statement_execute call is returning SQLDBC_OK.

char *tempstr = "CREATE TABLE TEST (NAME VARCHAR(20))";

rc = SQLDBC_Statement_execute(stmt,tempstr,strlen(tempstr),encodAsciiType);

if(SQLDBC_OK != rc) {

// org - fprintf(stderr, "Execution failed %s", stmt->error().getErrorText());

fprintf(stderr, "Execution failed ");

return (1);

}

Does anyone has any clue.

Also, i think database studio is not getting refreshed properly. I had to close the connection to a particular db and relogin to see the effect of dropping a table from sqlcli.

Regards

Raja

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

you are right and you are wrong.

There are database systems who do an implicit commit BEFORE and AFTER each DDL.

But it cannot be named 'naturally'.

There are database systems who are even able to rollback DDL-commands.

And MaxDB belongs to those database systems NOT doing an implicit commit before or after a DDL. Therefore the user has to specify a commit explicitly.

Elke

Answers (3)

Answers (3)

Former Member
0 Kudos

Short answer: yes.

Elke

Former Member
0 Kudos

Thanks Elke. That was very informative.

So, Can we do rollback of DDL statements in MaxDB ?

Regards

Raja

markus_doehr2
Active Contributor
0 Kudos

> When i run the same program today it's not working. I know that sounds very strange. But that's how it is.

If you would tell what "is not working" we could maybe help. Just stating "it does not" just leads to wild guesses.

Markus

Former Member
0 Kudos

Sorry for not providing the details of whats not working. Actually the table is not getting created. Its a simple program which creates a table by using SQLDBC. I have already checked things like creating the table from sqlcli and then dropping it, thats working. Also like i said earlier the execution of statement is returning SQLDBC_OK.

Regards

Raja

lbreddemann
Active Contributor
0 Kudos

Hi Raja,

just a wild guess - did you possibly change the connection parameter "AUTOCOMMIT" from TRUE to FALSE?

If so, you would have to issue a COMMIT before any other session would be able to see your table.

regards,

Lars

Former Member
0 Kudos

Hi Lars,

No i didn't change. Anyways the program code is very little so am copy pasting here. Please see if you can help.

-


Code starts----


#include "SQLDBC_C.h"

#include "stdio.h"

#include "string.h"

typedef struct ConnectArgsT {

char * username;

char * password;

char * dbname;

char * host;

} ConnectArgsT;

static void parseArgs (ConnectArgsT * connectArgs, int argc, char **argv);

int main(int argc, char *argv[])

{

ConnectArgsT connectArgs;

parseArgs (&connectArgs, argc, argv);

char errorText[200];

/*

  • Every application has to initialize the SQLDBC library by getting a

  • reference to the ClientRuntime and calling the SQLDBC_Environment constructor.

*/

SQLDBC_IRuntime *runtime;

runtime = ClientRuntime_GetClientRuntime(errorText, (SQLDBC_Int4) sizeof(errorText));

if (!runtime) {

fprintf(stderr, "Getting instance of the ClientRuntime failed %s", errorText);

return (1);

}

SQLDBC_Environment* env = SQLDBC_Environment_new_SQLDBC_Environment(runtime);

if (!env) {

fprintf(stderr, "Getting Environment of the SQLDBC failed %s", errorText);

return (1);

}

/*

  • Create a new connection object and open a session to the database.

*/

SQLDBC_Connection *conn = SQLDBC_Environment_createConnection(env);

if (!conn) {

fprintf(stderr, "Getting Connection object failed ");

return (1);

}

SQLDBC_Retcode rc;

// For encoding

SQLDBC_StringEncodingType_Encoding encodAsciiType = SQLDBC_StringEncodingType_Encoding_Ascii;

SQLDBC_ConnectProperties* connpros = SQLDBC_ConnectProperties_new_SQLDBC_ConnectProperties();

rc = SQLDBC_Connection_connect(conn, connectArgs.host, (SQLDBC_Length) strlen(connectArgs.host),

connectArgs.dbname, (SQLDBC_Length) strlen(connectArgs.dbname),

connectArgs.username, (SQLDBC_Length) strlen(connectArgs.username),

connectArgs.password, (SQLDBC_Length) strlen(connectArgs.password),

encodAsciiType,connpros);

if(SQLDBC_OK != rc) {

SQLDBC_ErrorHndl *errHndl = SQLDBC_Connection_getError(conn);

fprintf(stderr, "Connecting to the database failed %s", SQLDBC_ErrorHndl_getErrorText(errHndl));

return (1);

}

/*

  • Create a new statment object and execute it.

*/

SQLDBC_Statement *stmt = SQLDBC_Connection_createStatement(conn);

if ( stmt == NULL )

fprintf(stderr, "createStatement failed ");

char *tempstr = "CREATE TABLE TEST (NAME VARCHAR(20))";

rc = SQLDBC_Statement_execute(stmt,tempstr,strlen(tempstr),encodAsciiType);

if(SQLDBC_OK != rc) {

fprintf(stderr, "Execution failed ");

return (1);

}

return 0;

}

static void parseArgs (ConnectArgsT * connectArgs, int argc, char **argv)

{

/*

  • setting defaults for demo database

*/

connectArgs->username = "MONA";

connectArgs->password = "RED";

connectArgs->dbname = "MAXDB1";

connectArgs->host = "";

/*

  • use values from command line

*/

if (argc > 4) {

connectArgs->host = argv [4];

}

if (argc > 3) {

connectArgs->dbname = argv [3];

}

if (argc > 2) {

connectArgs->password = argv [2];

}

if (argc > 1) {

connectArgs->username = argv [1];

}

}

Former Member
0 Kudos

Hey Lars,

Good News. Your wild guess was absolutely right but with a little twist.

I just executed a commit after the table creation execute in the above program and it started working.

But i have something to understand here. Table creation is DDL statement, and i think DDL statement by nature don't require a commit.

Then why do we have to give a commit here.

Regards

Raja