Пример #1
0
static void _php_ibase_commit_link(ibase_db_link *link) /* {{{ */
{
	unsigned short i = 0, j;
	ibase_tr_list *l;
	ibase_event *e;
	IBDEBUG("Checking transactions to close...");

	for (l = link->tr_list; l != NULL; ++i) {
		ibase_tr_list *p = l;
		if (p->trans != 0) {
			if (i == 0) {
				if (p->trans->handle != 0) {
					IBDEBUG("Committing default transaction...");
					if (isc_commit_transaction(IB_STATUS, &p->trans->handle)) {
						_php_ibase_error();
					}
				}
				efree(p->trans); /* default transaction is not a registered resource: clean up */
			} else {
				if (p->trans->handle != 0) {
					/* non-default trans might have been rolled back by other call of this dtor */
					IBDEBUG("Rolling back other transactions...");
					if (isc_rollback_transaction(IB_STATUS, &p->trans->handle)) {
						_php_ibase_error();
					}
				}
				/* set this link pointer to NULL in the transaction */
				for (j = 0; j < p->trans->link_cnt; ++j) {
					if (p->trans->db_link[j] == link) {
						p->trans->db_link[j] = NULL;
						break;
					}
				}
			}
		}
		l = l->next;
		efree(p);
	}
	link->tr_list = NULL;

	for (e = link->event_head; e; e = e->event_next) {
		_php_ibase_free_event(e);
		e->link = NULL;
	}
}
Пример #2
0
/*
** GCs an connection object
*/
static int conn_gc (lua_State *L) {
    conn_data *conn = (conn_data *)luaL_checkudata(L,1,LUASQL_CONNECTION_FIREBIRD);

    if(conn->closed == 0) {
        if(conn->autocommit != 0)
            isc_commit_transaction(conn->env->status_vector, &conn->transaction);
        else
            isc_rollback_transaction(conn->env->status_vector, &conn->transaction);

        isc_detach_database(conn->env->status_vector, &conn->db);

        conn->closed = 1;
        --conn->env->lock;

        /* check environment can be GC'd */
        if(conn->env->lock == 0)
            lua_unregisterobj(L, conn->env);
    }

    return 0;
}
Пример #3
0
int query( char * sel_str )
{
   ISC_STATUS status[ 20 ];
   XSQLVAR *  var;

   int n, i, dtype;

   if( isc_start_transaction( status, &trans, 1, &db, 0, NULL ) )
      ERREXIT( status, 1 );

   /* Allocate an output SQLDA. Just to check number of columns */
   sqlda          = ( XSQLDA * ) malloc( XSQLDA_LENGTH( 1 ) );
   sqlda->sqln    = 1;
   sqlda->version = 1;

   /* Allocate a statement */
   if( isc_dsql_allocate_statement( status, &db, &stmt ) )
      ERREXIT( status, 1 );

   /* Prepare the statement. */
   if( isc_dsql_prepare( status, &trans, &stmt, 0, sel_str, dialect, sqlda ) )
      ERREXIT( status, 1 );

   /* Describe sql contents */
   if( isc_dsql_describe( status, &stmt, dialect, sqlda ) )
      ERREXIT( status, 1 );

   /* Relocate necessary number of columns */
   if( sqlda->sqld > sqlda->sqln )
   {
      free( sqlda );
      n              = sqlda->sqld;
      sqlda          = ( XSQLDA * ) malloc( XSQLDA_LENGTH( n ) );
      sqlda->sqln    = n;
      sqlda->version = 1;

      if( isc_dsql_describe( status, &stmt, dialect, sqlda ) )
         ERREXIT( status, 1 );
   }

   for( i = 0, var = sqlda->sqlvar; i < sqlda->sqld; i++, var++ )
   {
      dtype = ( var->sqltype & ~1 );
      switch( dtype )
      {
         case SQL_VARYING:
            var->sqltype = SQL_TEXT;
            var->sqldata = ( char * ) malloc( sizeof( char ) * var->sqllen + 2 );
            break;
         case SQL_TEXT:
            var->sqldata = ( char * ) malloc( sizeof( char ) * var->sqllen + 2 );
            break;
         case SQL_LONG:
            var->sqltype = SQL_LONG;
            var->sqldata = ( char * ) malloc( sizeof( long ) );
            break;
         default:
            var->sqldata = ( char * ) malloc( sizeof( char ) * var->sqllen );
            break;
      }
      if( var->sqltype & 1 )
      {
         var->sqlind = ( short * ) malloc( sizeof( short ) );
      }
   }

   if( ! sqlda->sqld )
   {
      /* Execute and commit non-select querys */
      if( isc_dsql_execute( status, &trans, &stmt, dialect, NULL ) )
         ERREXIT( status, 1 );

      if( isc_commit_transaction( status, &trans ) )
         ERREXIT( status, 1 );

      trans = NULL;

   }
   else
   {
      if( isc_dsql_execute( status, &trans, &stmt, dialect, sqlda ) )
         ERREXIT( status, 1 );
   }

   return 1;
}
Пример #4
0
ISC_STATUS API_ROUTINE gds__commit_transaction(ISC_STATUS* status_vector, FB_API_HANDLE *tra_handle)
{
	return isc_commit_transaction(status_vector, tra_handle);
}