Skip to Content.
Sympa Menu

freetds - Re: [freetds] ODBC transaction unit test

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: John Anderson <ardour AT semiosix.com>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] ODBC transaction unit test
  • Date: Sun, 19 Oct 2003 13:52:25 -0000

On Sun, 2003-10-19 at 13:42, John Anderson wrote:
> On Sun, 2003-10-19 at 13:11, John Anderson wrote:
> > As requested, I've added a unit test (in transaction.c) to
> > odbc/unittests to expose the ODBC transaction error. Also, I added a
> > function to common.c - in the diff along with Makefile.am additions.
>
> For some reason the second attachment didn't get through...

Seems to have been stripped off again. So I'm sending it inline:

#include "common.h"

static char software_version[] = "$Id: getdata.c,v 1.1 2003/08/29 15:07:11
freddy77 Exp $";
static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };

int
main(int argc, char *argv[])
{
char buf[16];
int result = 0;
int retcode = 0;
char * createProcedure = ""
"CREATE PROCEDURE testinsert\n"
"@value int\n"
"AS\n"
"insert into TestTransaction values ( @value )\n"
"select * from TestTransaction\n"
;

Connect();

/* create table */
CommandWithResult(Statement, "DROP TABLE TestTransaction");
result = CommandWithResult(Statement, "CREATE TABLE TestTransaction (
value int )");
if (result != SQL_SUCCESS) {
printf("Can't create table TestTransaction\n");
CheckReturn();
retcode = 1;
goto cleanup;
}

/* create stored proc */
CommandWithResult(Statement, "DROP PROCEDURE testinsert");

result = CommandWithResult(Statement, createProcedure);
if (result != SQL_SUCCESS) {
printf("Can't create proc testinsert\n");
CheckReturn();
retcode = 1;
goto cleanup;
}

/* Start transaction */
result = SQLSetConnectAttr (
Connection
, SQL_ATTR_AUTOCOMMIT
, (void*)SQL_AUTOCOMMIT_OFF
, 0
);
if (result != SQL_SUCCESS) {
printf("Can't start transaction\n");
CheckReturn();
retcode = 1;
goto cleanup;
}

/* Insert a value */
Command(Statement, "EXEC testinsert 1");

/* Commit transaction */
result = SQLEndTran (
SQL_HANDLE_DBC
, Connection
, SQL_COMMIT
);
if (result != SQL_SUCCESS) {
printf("Can't commit transaction\n");
CheckReturn();
retcode = 1;
goto cleanup;
}

/* Start transaction */
result = SQLSetConnectAttr (
Connection
, SQL_ATTR_AUTOCOMMIT
, (void*)SQL_AUTOCOMMIT_OFF
, 0
);
if (result != SQL_SUCCESS) {
printf("Can't start transaction\n");
CheckReturn();
retcode = 1;
goto cleanup;
}

/* Insert another value */
Command(Statement, "EXEC testinsert 2");

/* Roll back transaction */
result = SQLEndTran (
SQL_HANDLE_DBC
, Connection
, SQL_ROLLBACK
);
if (result != SQL_SUCCESS) {
printf("Can't roll back transaction\n");
CheckReturn();
retcode = 1;
goto cleanup;
}

cleanup:
/* drop table */
CommandWithResult(Statement, "DROP PROCEDURE testinsert");
CommandWithResult(Statement, "DROP TABLE TestTransaction");

Disconnect();

printf("Done.\n");
return retcode;
}






Archive powered by MHonArc 2.6.24.

Top of Page