예제 #1
0
int main(int argc, char **argv) {
	char working_dir[PATH_MAX];

	/* Check we are running as root */
	debug_return(geteuid() == 0, EACCES, "%s", "Please, run the program as root!\n");

	/* Get directory in which tests are to be run */
	if (argc > 1) {
		strncpy(working_dir, argv[1], sizeof(working_dir) / sizeof(working_dir[0]));
		/* And try to move to it */
		debug_return(chdir(working_dir) != -1, errno, "working_dir=\"%s\" errno=%d\n", working_dir, errno);
	} else {
		getcwd(working_dir, sizeof(working_dir));
		/* Nothing more to do, we're still there */
	}

	debug_out("Will execute tests on: %s\n", working_dir);

	/* Quickly check whether tree looks good */
	debug_return(check_tree_dir("export/") != -1, errno, "Failed stat() on export directory, errno = %d\n", errno);
	debug_return(check_tree_dir("root/") != -1, errno, "Failed stat() on root directory, errno = %d\n", errno);
	debug_return(check_tree_dir("snapshot/") != -1, errno, "Failed stat() on snapshot directory, errno = %d\n", errno);

	/* Start tests */
	do_tests(working_dir);

	return 0;
}
예제 #2
0
static int
col_list_addColumn_blob_S(
    odbcdr_blob_col_list_def *list,
    int                      position_I,
    pByteArray_def          *address_I
    )
{
    odbcdr_blob_col_def       newColumn = initialisedColumn_blob_S;
    int                      rdbi_status = RDBI_GENERIC_ERROR;

    debug_on2( "odbcdr_blob:col_list_addColumn_blob_S", "pos %d, address 0x%lx",
                                            position_I, (long) address_I );

    if ( list == NULL || position_I < 1 || address_I == NULL ) goto the_exit;

    newColumn.position = position_I;
    newColumn.address  = address_I;

    if ( ut_da_append( list, 1L, (void *) &newColumn ) == NULL ) {
        rdbi_status = RDBI_MALLOC_FAILED;
        goto the_exit;
    }

    rdbi_status = RDBI_SUCCESS;

  the_exit:
    debug_return( NULL, rdbi_status );
}
예제 #3
0
int rdbi_col_actW(
    rdbi_context_def *context,
    const wchar_t *owner,
    const wchar_t *object_name,
    const wchar_t *dbaselink
)
{
    int     status;
    int     tran_begun = FALSE;


    debug_on2("rdbi_col_actW", "owner='%ls', object='%ls'", ISNULL(owner), ISNULL(object_name));

    if (context->rdbi_cnct->autocommit_on) {
        rdbi_tran_begin(context, tran_id);
        tran_begun = TRUE;
    }

    status = (*(context->dispatch.col_actW))(context->drvr, owner, object_name, dbaselink);

    context->rdbi_last_status = status;

    /* ingdr_col_act prefetches all columns so its safe to end the transaction
    *   here without getting fetch across commit problems.
    */

    if ( tran_begun ) {
        rdbi_tran_end(context, tran_id);
    }

    debug_return(NULL, status);
}
예제 #4
0
int rdbi_col_getW(
	rdbi_context_def *context,
    wchar_t *column_name,
    wchar_t *type,
    int  *length,
    int  *scale,
    int  *nullable,
    int  *is_autoincrement,
    int  *position,
    int  *eof)
{
    int   status;

    debug_on("rdbi_col_getW");

    status = (*(context->dispatch.col_getW))(context->drvr, column_name, type, length, scale, nullable, is_autoincrement,
                            position, eof);

    context->rdbi_last_status = status;

    debug_area()
    {
        if (*eof)
        {
            debug0("eof=TRUE");
        }
        else
        {
            debug6("column='%ls', type='%ls', length=%d, scale=%d, nullable=%s, position=%d",
                ISNULL(column_name), ISNULL(type), *length, *scale, ISTRUE(*nullable), *position);
        }
    }
    debug_return(NULL, status);
}
예제 #5
0
int rdbi_objects_actW(
	rdbi_context_def *context,
    const wchar_t *owner,
    const wchar_t *target)
{
    int     status;
    int     tran_begun = FALSE;

    debug_on("rdbi_objects_actW");

    if (context->rdbi_cnct->autocommit_on) {
        rdbi_tran_begin(context, tran_id);
        tran_begun = TRUE;
    }

    status = (*(context->dispatch.objects_actW))(context->drvr, owner, target);

    context->rdbi_last_status = status;

    /* This code is based on rdbi_col_act, which assumes that prefetches 
    * occur, making it safe to end the transaction
    * without getting fetch across commit problems.  We'll do the same.
    */

    if ( tran_begun ) {
        rdbi_tran_end(context, tran_id);
    }

    debug_return(NULL, status);
}
예제 #6
0
int rdbi_objects_deac(rdbi_context_def *context)
{
    int   status;

    debug_on("rdbi_objects_deac");

    status = (*(context->dispatch.objects_deac))(context->drvr);

    context->rdbi_last_status = status;

    debug_return(NULL, status);

}
예제 #7
0
int
odbcdr_xlt_status(		 /* Return RDBI equiv of SQL Server status  */
    odbcdr_context_def  *context,
	SQLRETURN odbcdr_status,
	SQLSMALLINT handle_type,
	SQLHANDLE handle 	
	)
{
	int		rdbi_status = RDBI_GENERIC_ERROR;

	debug_on1( "odbcdr_xlt_status","ODBC status: %d", odbcdr_status );

	switch( odbcdr_status ) {

		case SQL_SUCCESS :
   		case SQL_SUCCESS_WITH_INFO :
			rdbi_status = RDBI_SUCCESS;
			break;

		/* DS: THIS IS NOT TRUE!
		** SQL_SUCESS_WITH_INFO is returned after executing array DML, if
		** there are ignorable errors or if a row operation failed.
		** Therefore, we need to search the diagnostic record to see if any
		** real errors occured.

        /*
		** In the SQL_ERROR case, we need to check if we can convert it to a
		** more specific database error type. The message is saved in the
		** context->odbcdr_last_err_msg field.
		*/
		case SQL_ERROR :
			rdbi_status = get_error_from_diag_rec(context, handle_type, handle);
			break;
		case SQL_NO_DATA :
			rdbi_status = RDBI_END_OF_FETCH;
			break;
		case SQL_NEED_DATA :
		case SQL_INVALID_HANDLE :
		case SQL_STILL_EXECUTING :
			rdbi_status = RDBI_GENERIC_ERROR;
            if (context->odbcdr_UseUnicode)
			    save_err_msgW(context, handle_type, handle, 1); // 1 = assuming a connection has already been made
            else
                save_err_msg(context, handle_type, handle, 1); // 1 = assuming a connection has already been made
			break;
		default:
			rdbi_status = RDBI_GENERIC_ERROR;
	}

	debug_return(NULL, rdbi_status);
}
예제 #8
0
int rdbi_stores_act(
	rdbi_context_def *context)
{
    int     status;

    debug_on("rdbi_stores_act");

    status = (*(context->dispatch.stores_act))(context->drvr);

    context->rdbi_last_status = status;

    debug_return(NULL, status);

}
예제 #9
0
int rdbi_stores_get(
	rdbi_context_def *context,
    char *name,
    int  *eof)
{
    int   status;

    debug_on("rdbi_stores_get");

    status = (*(context->dispatch.stores_get))(context->drvr, name, eof);

    context->rdbi_last_status = status;

    debug_return(NULL, status);
}
예제 #10
0
int rdbi_objects_getW(
	rdbi_context_def *context,
    wchar_t *name,
    wchar_t *type,
    int  *eof)
{
    int   status;

    debug_on("rdbi_objects_get");

    status = (*(context->dispatch.objects_getW))(context->drvr, name, type, eof);

    context->rdbi_last_status = status;

    debug_return(NULL, status);
}
예제 #11
0
int rdbi_usr_existsW(
	rdbi_context_def *context,
    wchar_t *user_name,
    int  *exists)
{
    int   status;

    debug_on("rdbi_usr_exists");

    status = (*(context->dispatch.usr_existsW))(context->drvr, user_name, exists);

    context->rdbi_last_status = status;

    debug_return(NULL, status);

}
예제 #12
0
static bool
col_list_free_blob_S(
	odbcdr_context_def	*context,
    odbcdr_blob_col_list_def *list
    )
{
    long                     i;
    bool                     status = true;
    int                      rdbi_status = RDBI_GENERIC_ERROR;

    debug_on1( "odbcdr_blob:col_list_free_blob_S", "%ld columns",
                (list==NULL)? -1 : list->size );

    if ( list == NULL ) goto the_exit;

    if ( !col_list_freeSqlServerBlobs_S( context, list ) ) goto the_exit;

    for ( i = 0;  i < list->size;  i++ ) {

        odbcdr_blob_col_def  *column = col_list_getColumnByIndex_blob_S( list, i );

        /* Free the arrays themselves. */
        debug1( "Freeing pointers for %ld blobs.",
                column->blob_list.size );

		for ( int j = 0; j < column->blob_list.size; j++ ) {
			IByteArray_Release( column->l_address[j] );	
		}

		ut_vm_free( _db_function, column->l_address );

        status &= ut_da_free( &(column->blob_list) );
        status &= ut_da_free( &(column->blobNI_list) );
    }

    rdbi_status = RDBI_SUCCESS;

    debug1( "Freeing %ld blob columns.", list->size );
    status &= ut_da_free( list ); 

  the_exit:

    status &= ( rdbi_status == RDBI_SUCCESS );
    
    debug_return( NULL, status );
}
예제 #13
0
int rdbi_initialize (rdbi_context_def **contextp, char* driver)
{
    DWORD nchars;
    char module[MAX_PATH];
    char* last;
    HMODULE handle;
    FARPROC procedure;
    int status;

    debug_on("rdbi_initialize");

    nchars = GetModuleFileName (NULL, module, MAX_PATH);
    if (0 == nchars)
        strcpy (module, ".\\");
    else
    {   
        // scan the string for the last occurrence of a slash
        last = strrchr (module, '\\');
        if (NULL != last)
        {
            last++; // move past the slash
            *last = '\0'; // null terminate it there
        }
    }
    strcat (module, driver);
#ifdef _WIN32
    strcat (module, ".dll");
#else
    strcat (module, ".so"); // doesn't really work here, just a placeholder
#endif
    handle = LoadLibrary (module);
    if (NULL != handle)
    {
        procedure = GetProcAddress (handle, "init");
        if (NULL != procedure)
            status = rdbi_init (contextp, (initializer*)procedure);
        else
            status = RDBI_GENERIC_ERROR;
    }
    else
        status = RDBI_GENERIC_ERROR;
    
    debug_return(NULL, status);
}
예제 #14
0
int
rdbi_tran_begin(
rdbi_context_def *context,
char    *tran_id )
{

    tran_entry_def  *tran_entry;
    int              status;


    debug_on3("rdbi_tran_begin", "New tran id [%s.R%d:'%s']",
                    context->rdbi_cnct->db_name, context->rdbi_cnct->connect_id, ISNULL(tran_id));

    status = FALSE;
    if (tran_id == NULL || strcmp(tran_id, "") == 0)    {
        rdbi_msg_set_0(context, RDBI_20, "Illegal (null or empty) transaction id.");
        goto the_exit;
    }

    if (context->rdbi_cnct == NULL) {
        rdbi_msg_set_S(context, RDBI_21, "No current database is open; cannot begin transaction '%1$ls' .", tran_id);
        goto the_exit;
    }

    tran_entry = (tran_entry_def *)ut_vm_malloc("rdbi_tran_begin",
                                            sizeof(struct tran_entry_def));
    if (tran_entry == NULL) goto the_exit;

    if( context->rdbi_cnct->tran_head == NULL && context->dispatch.tran_begin != NULL )
    {
        (*(context->dispatch.tran_begin))(context->drvr);
    }
    strncpy(tran_entry->tran_id, tran_id, sizeof(tran_entry->tran_id));
    tran_entry->tran_id[sizeof(tran_entry->tran_id)-1] = '\0';
    tran_entry->tran_ended  = FALSE;
    tran_entry->next        = context->rdbi_cnct->tran_head;
    context->rdbi_cnct->tran_head    = tran_entry;

    status = TRUE;

the_exit:
    debug_return(NULL, status);
}
예제 #15
0
static int
col_list_setNumRows_blob_S(
    odbcdr_blob_col_list_def *list,
    int                      numRows_I
    )
{
    long                     i;
    int                      rdbi_status = RDBI_GENERIC_ERROR;

    debug_on1( "odbcdr_blob:col_list_setNumRows_blob_S", "numRows %d", numRows_I );

    if ( list == NULL || numRows_I < 1 ) goto the_exit;

    for ( i = 0;  i < list->size;  i++ ) {

        odbcdr_blob_col_def  *column = col_list_getColumnByIndex_blob_S( list, i );

        if ( !ut_da_presize( &column->blob_list, numRows_I ) ) {
            rdbi_status = RDBI_MALLOC_FAILED;
            goto the_exit;
        }

        if ( !ut_da_presize( &column->blobNI_list, numRows_I ) ) {
            rdbi_status = RDBI_MALLOC_FAILED;
            goto the_exit;
        }

		if ( column->l_address == NULL ) {
			column->l_address = (pByteArray_def *) malloc (numRows_I * sizeof(pByteArray_def));
			if ( column->l_address == NULL ) {
				rdbi_status = RDBI_MALLOC_FAILED;
				goto the_exit;
			}
			memset( column->l_address, '\0', numRows_I * sizeof(pByteArray_def));
		}
    }

    rdbi_status = RDBI_SUCCESS;

  the_exit:
    debug_return(NULL, rdbi_status );
}
예제 #16
0
static bool
col_list_freeSqlServerBlobs_S(
	odbcdr_context_def	*context,
    odbcdr_blob_col_list_def *list
    )
{
    long                     i, j;
    bool                     status = true;
    int                      rdbi_status = RDBI_GENERIC_ERROR;

    debug_on1( "odbcdr_blob:col_list_freeSqlServerBlobs_S", "%ld columns",
                (list==NULL)? -1 : list->size );

    if ( list == NULL ) goto the_exit;

    for ( i = 0;  i < list->size;  i++ ) {

        odbcdr_blob_col_def  *column = col_list_getColumnByIndex_blob_S( list, i );

        for ( j = 0; j < column->blob_list.size; j++ )
        {
			odbcdr_blob_def *blob = *((odbcdr_blob_def **)ut_da_get( &column->blob_list, j ));
			odbcdr_blobNI_def *blobNI = *((odbcdr_blobNI_def **)ut_da_get( &column->blobNI_list, j ));
        }

        /* Just zero out the pointers. */
        debug1( "Zeroing out pointers for %ld blobs.",
                column->blob_list.size );
        (void) memset( column->blob_list.data, 0,
             (size_t) column->blob_list.el_size * column->blob_list.size );
        (void) memset( column->blobNI_list.data, 0,
             (size_t) column->blobNI_list.el_size * column->blobNI_list.size );
    }

    rdbi_status = RDBI_SUCCESS;

  the_exit:

    status &= ( rdbi_status == RDBI_SUCCESS );
    
    debug_return( NULL, status );
}
예제 #17
0
odbcdr_cursor_def *odbcdr_crt_cursor(
    odbcdr_context_def *context,
	odbcdr_cursor_def	*old_cursor
	)
{
	odbcdr_cursor_def	*c;

	debug_on1("odbcdr_crt_cursor", "c: 0x%p", old_cursor);

	if(old_cursor)
		c = old_cursor;
	else {
		c = (odbcdr_cursor_def *)
			ut_vm_malloc( "odbcdr_crt_cursor", sizeof( odbcdr_cursor_def ) );
		memset((char *)c, '\0', sizeof(odbcdr_cursor_def)); // cmb
	}

	if( c == (odbcdr_cursor_def *)NULL ) goto the_exit;

	// Initialize all struct elements
	c->sqlstring		    = (char *)NULL;
	c->hStmt                = (odbcdr_cursor_handle_def) NULL;
	c->next				    = (odbcdr_cursor_def *)NULL;
	c->cumul_rows_fetched   = 0;
	c->is_rollback		    = FALSE;
    c->odbcdr_geom          = NULL;
    c->odbcdr_geomNI        = NULL;
    c->odbcdr_blob_tmp      = NULL;
    c->odbcdr_blob_tmp_size = 0;
    c->odbcdr_geom_handle   = NULL;
    c->geom_srid_maping     = NULL;
    c->geom_type_maping     = NULL;
    c->geom_version_value   = 1;
    c->odbcdr_blob          = NULL;
    c->odbcdr_blobNI        = NULL;
    c->defined_blobs        = NULL;
    c->len_idf_maping       = NULL;

the_exit:
	debug_return (NULL,c);
}
예제 #18
0
int odbcdr_define(
    odbcdr_context_def *context,
	char	*cursor,
	char	*name,
	int 	 datatype,
	int 	 size,
	char	*address,
	SQLLEN	*null_ind
	)
{
	odbcdr_cursor_def	*c;
	int 				position;
	//int 				atoi();
	int 				odbcdr_datatype;
	int 				odbcdr_size;
	int 				rdbi_status = RDBI_GENERIC_ERROR;
	SQLRETURN			rc = ODBCDR_SUCCESS;
	int					is_numeric = TRUE;	/* no alphabetic name support */

	debug_on5("odbcdr_define","c:%#x name: %s type: %d address: 0x%lx size: %d",
							cursor, name, datatype, (long) address, size);

	ODBCDR_RDBI_ERR( odbcdr_get_cursor( context, cursor, &c ) );

	position = atoi(name);	/* Numeric positions are the only valid input	*/

	odbcdr_get_o_t_s( context, datatype, size, &odbcdr_datatype, &odbcdr_size );

    // Spetial handling for Geometries
    if ( datatype != RDBI_GEOMETRY )
	{
        if ( datatype != RDBI_BLOB_ULEN && datatype != RDBI_WSTRING_ULEN && datatype != RDBI_STRING_ULEN)
        {
            ODBCDR_ODBC_ERR( SQLBindCol( c->hStmt,
									(SQLUSMALLINT) position,
									(SQLSMALLINT) odbcdr_datatype,
									(SQLPOINTER) address,
									(SQLINTEGER) size,
									(SQLLEN *) null_ind),
							SQL_HANDLE_STMT, c->hStmt,
							"SQLBindCol", "define" );
        }
        else // RDBI_BLOB_ULEN , RDBI_WSTRING_ULEN , RDBI_STRING_ULEN
        {
            ODBCDR_RDBI_ERR( odbcdr_blob_defineColumn(context, c, position, address));

            ODBCDR_RDBI_ERR( odbcdr_blob_setNumRows(context, c, ODBCDR_MAX_ARRAY_SIZE));

            // Allocate the buffers for blobs and Null indicators
            int numBlobCols = c->defined_blobs->size;
            if ( numBlobCols == 1 )
            {
                c->odbcdr_blob = (PBYTE)malloc( ODBCDR_MAX_ARRAY_SIZE * ODBCDR_UBLOB_CHUNK_SIZE );
                c->odbcdr_blobNI = (SQLLEN *)malloc( ODBCDR_MAX_ARRAY_SIZE * sizeof(SQLLEN));
            }
            else
            {  
                c->odbcdr_blob = (PBYTE)realloc( c->odbcdr_blob, numBlobCols * ODBCDR_MAX_ARRAY_SIZE * ODBCDR_UBLOB_CHUNK_SIZE );
                c->odbcdr_blobNI = (SQLLEN *)realloc( c->odbcdr_blobNI, numBlobCols * ODBCDR_MAX_ARRAY_SIZE * sizeof(SQLLEN));
            }

            // Do binds (the previous bound columns will be rebound because of reallocation)
            for ( int i = 0; i < numBlobCols; i++ )
            {
                odbcdr_blob_col_def *column = (odbcdr_blob_col_def *) ut_da_get( c->defined_blobs, i );

                int offset = i * ODBCDR_MAX_ARRAY_SIZE;

	            ODBCDR_ODBC_ERR( SQLBindCol( c->hStmt,
								            (SQLUSMALLINT) column->position,
								            (SQLSMALLINT)  odbcdr_datatype,
                                            (SQLPOINTER)   (char *)&c->odbcdr_blob[offset * ODBCDR_UBLOB_CHUNK_SIZE],
                                            (SQLINTEGER)   ODBCDR_UBLOB_CHUNK_SIZE,
								            (SQLLEN *)     (char *)&c->odbcdr_blobNI[offset]),
						            SQL_HANDLE_STMT, c->hStmt,
						            "SQLBindCol", "define" );
            }
        }
	}
	else
	{
        ODBCDR_RDBI_ERR( odbcdr_geom_defineColumn(context, c, position, address));

        ODBCDR_RDBI_ERR( odbcdr_geom_setNumRows(context, c, ODBCDR_MAX_ARRAY_SIZE));

        // Allocate the buffers for Geometries and Null indicators
        int numGeomCols = c->defined_geometries->size;
        if ( numGeomCols == 1 )
        {
            c->odbcdr_geom = (PBYTE)malloc( ODBCDR_MAX_ARRAY_SIZE * ODBCDR_BLOB_CHUNK_SIZE );
            c->odbcdr_geomNI = (SQLLEN *)malloc( ODBCDR_MAX_ARRAY_SIZE * sizeof(SQLLEN));
        }
        else
        {  
            c->odbcdr_geom = (PBYTE)realloc( c->odbcdr_geom, numGeomCols * ODBCDR_MAX_ARRAY_SIZE * ODBCDR_BLOB_CHUNK_SIZE );
            c->odbcdr_geomNI = (SQLLEN *)realloc( c->odbcdr_geomNI, numGeomCols * ODBCDR_MAX_ARRAY_SIZE * sizeof(SQLLEN));
        }

        // Do binds (the previous bound columns will be rebound because of reallocation)
        for ( int i = 0; i < numGeomCols; i++ )
        {
            odbcdr_geom_col_def *column = (odbcdr_geom_col_def *) ut_da_get( c->defined_geometries, i );

            int offset = i * ODBCDR_MAX_ARRAY_SIZE;

	        ODBCDR_ODBC_ERR( SQLBindCol( c->hStmt,
								        (SQLUSMALLINT) column->position,
								        (SQLSMALLINT)  odbcdr_datatype,
                                        (SQLPOINTER)   (char *)&c->odbcdr_geom[offset * ODBCDR_BLOB_CHUNK_SIZE],
                                        (SQLINTEGER)   ODBCDR_BLOB_CHUNK_SIZE,
								        (SQLLEN *)     (char *)&c->odbcdr_geomNI[offset]),
						        SQL_HANDLE_STMT, c->hStmt,
						        "SQLBindCol", "define" );
        }

    }   /* end if datatype == RDBI_GEOMETRY */

	rdbi_status = RDBI_SUCCESS;

the_exit:
	debug1("Returning cursor c:%#x", cursor);
	debug_area() odbcdr_show_context( context, c );
	debug_return(NULL, rdbi_status );
}
예제 #19
0
int odbcdr_fre_cursor(
    odbcdr_context_def  *context,
	char   **cursor
	)
{
	odbcdr_cursor_def	*c;
	odbcdr_connData_def	*connData;
	odbcdr_cursor_def	*parent_cursor; 	/* For traversing cursor list	*/
	SQLRETURN			rc;
	int					rdbi_status = RDBI_GENERIC_ERROR;
	//int					i;

	debug_on1("odbcdr_fre_cursor", "s:0x%p", *cursor);

	ODBCDR_RDBI_ERR( odbcdr_get_cursor( context, *cursor, &c ) );

	ODBCDR_RDBI_ERR( odbcdr_get_curr_conn( context, &connData) );

	/* Remove this cursor from the connection's linked list of cursors */
	parent_cursor = connData->cursors;
	if( parent_cursor == c ) {
		connData->cursors = c->next;
	} else {
		while( parent_cursor != (odbcdr_cursor_def *)NULL &&
			   parent_cursor->next != c ) {

			parent_cursor = parent_cursor->next;
		}
		if( parent_cursor != (odbcdr_cursor_def *)NULL ) {
			parent_cursor->next = c->next;
		}
		else {
            // ERROR: Cursor not found
            // Needs a message catalog...
			//nls_msg_issue('s', MF_OCIDR, S_OCIDR_1, OCIDR_1, "Cursor not found.");
			goto the_exit;
		}
	}

	/*
	** Free the statement handle
	*/
	rc = SQLFreeHandle(SQL_HANDLE_STMT, c->hStmt);
	if ( rc != ODBCDR_SUCCESS )
	{
		debug0( "SQLFreeHandle for cursor FAILED!" );
		/* Don't exit, even if error. */
		rdbi_status = odbcdr_xlt_status( context, rc, SQL_HANDLE_STMT, c->hStmt );
	}
	c->hStmt = NULL;

	c->cumul_rows_fetched = 0;

	/*
	** Deallocate the string memory
	*/
	if(c->sqlstring != NULL) {
		ut_vm_free( _db_function, c->sqlstring );
		c->sqlstring = NULL;
	}

    // Free the working buffer
    if ( c->odbcdr_geom != NULL )
        ut_vm_free( _db_function, c->odbcdr_geom );

    if ( c->odbcdr_geomNI != NULL )
        ut_vm_free( _db_function, c->odbcdr_geomNI );

    // Free the working buffer
    if ( c->odbcdr_blob_tmp != NULL )
        ut_vm_free( _db_function, c->odbcdr_blob_tmp );

	// Free the geometry buffers
    ODBCDR_RDBI_ERR( odbcdr_geom_freeAllColumns( context, c ) );   

	ut_vm_free( _db_function, (char *)c );
	c = NULL;

	*cursor = (char *)NULL;
	rdbi_status = RDBI_SUCCESS;

    // Sometimes the last error message is retrieved after the cursor is closed.
    // Clearing the error code means to inhibit reading the error message.
	//context->odbcdr_last_rc = ODBCDR_SUCCESS;

the_exit:
	debug_return(NULL, rdbi_status );
}
예제 #20
0
int odbcdr_fetch2(
    odbcdr_context_def  *context,
	char                *cursor,		/* cursor context area		*/
	int                 count,			/* # rows requested 		*/
	int		            do_exec,
	int		            do_cancel,
	int                 *rows_processed	/* # rows actually returned */
	)
{
	odbcdr_cursor_def	*c;
	SQLRETURN			rc;			/* ODBC return value */
	int 				rdbi_status = RDBI_SUCCESS;
	int					rows_in_last_fetch;

	debug_on4("odbcdr_fetch2", "c:%#x count: %d %sexec %scancel",
			cursor, count, do_exec?"do ":"no ", do_cancel?"do ":"no ");

	ODBCDR_RDBI_ERR( odbcdr_get_cursor(context, cursor, &c ) );
	assert(count <= ODBCDR_MAX_ARRAY_SIZE);

    if ( c->defined_geometries != NULL )
    {
        /* Free any Oracle objects from previous executions/fetches. */
        ODBCDR_RDBI_ERR( odbcdr_geom_freeSqlServerGeometries( context, c ) );

        /* Set array size to exactly that which is requested. */
        ODBCDR_RDBI_ERR( odbcdr_geom_setNumRows( context, c, count ) );

    }   /* end if geometries */

    if (context->odbcdr_UseUnicode)
    {
	    //Set the fetch size
	    SQLSetStmtAttrW( c->hStmt, SQL_ATTR_ROW_ARRAY_SIZE, (PTR)count, SQL_IS_INTEGER);

	    //Enable retreival of rows_processed
	    SQLSetStmtAttrW( c->hStmt, SQL_ATTR_ROWS_FETCHED_PTR, &rows_in_last_fetch, SQL_IS_POINTER);
    }
    else
    {
	    //Set the fetch size
	    SQLSetStmtAttr( c->hStmt, SQL_ATTR_ROW_ARRAY_SIZE, (PTR)count, SQL_IS_INTEGER);

	    //Enable retreival of rows_processed
	    SQLSetStmtAttr( c->hStmt, SQL_ATTR_ROWS_FETCHED_PTR, &rows_in_last_fetch, SQL_IS_POINTER);
    }

	// if using server cursors and if end of fetch, the value of rows
	// in last fetch will be garbage. Set it to 0 to get rid of the garbage
	rows_in_last_fetch = 0;

	if ( do_exec )
	{
		debug0("Running execfetch");
#ifdef _WIN32
		// Turn on autofetch
        if (context->odbcdr_UseUnicode)
		    SQLSetStmtAttrW( c->hStmt, SQL_SOPT_SS_CURSOR_OPTIONS, (PTR)SQL_CO_AF, SQL_IS_INTEGER);
        else
            SQLSetStmtAttr( c->hStmt, SQL_SOPT_SS_CURSOR_OPTIONS, (PTR)SQL_CO_AF, SQL_IS_INTEGER);
#endif

		rdbi_status = odbcdr_execute( context, cursor, 1, 0, rows_processed ); 
 
#ifdef _WIN32
        if (context->odbcdr_UseUnicode)
        {
		    // Turn off autofetch
		    SQLSetStmtAttrW( c->hStmt, SQL_SOPT_SS_CURSOR_OPTIONS, (PTR)SQL_CO_OFF, SQL_IS_INTEGER);

		    //Make sure we are still using fast forward cursors
		    SQLSetStmtAttrW( c->hStmt, SQL_SOPT_SS_CURSOR_OPTIONS, (PTR)SQL_CO_FFO, SQL_IS_INTEGER);
        }
        else
        {
		    // Turn off autofetch
		    SQLSetStmtAttr( c->hStmt, SQL_SOPT_SS_CURSOR_OPTIONS, (PTR)SQL_CO_OFF, SQL_IS_INTEGER);

		    //Make sure we are still using fast forward cursors
		    SQLSetStmtAttr( c->hStmt, SQL_SOPT_SS_CURSOR_OPTIONS, (PTR)SQL_CO_FFO, SQL_IS_INTEGER);
        }
#endif

		if ( rdbi_status != RDBI_SUCCESS &&
			rdbi_status != RDBI_END_OF_FETCH)
		{
			goto the_exit;
		}

		if (rdbi_status == RDBI_END_OF_FETCH)
		{
			SQLCloseCursor(c->hStmt);
		}

	}

	if (!do_exec){ // if do_exec was true, the fetch was already done in the call to odbcdr_execute()
		rc = SQLFetch( c->hStmt);

		if ( rc != SQL_SUCCESS &&
			 rc != SQL_SUCCESS_WITH_INFO &&
			 rc != SQL_NO_DATA)
		{
			debug0( "SQLFetch FAILED!" );
			rdbi_status = odbcdr_xlt_status( context, rc, SQL_HANDLE_STMT, c->hStmt);
			context->odbcdr_last_rc = rc;
			goto the_exit;
		}
		else
		{
			rdbi_status = odbcdr_xlt_status( context, rc, SQL_HANDLE_STMT, c->hStmt );
			debug0( "ODBCStmtFetch succeeded." );
			if (rc == SQL_NO_DATA)
			{
				SQLCloseCursor(c->hStmt);
			}
		}
	}

	/* 
	** In ODBC rows_processed is only for the LAST fetch 
	** (In OCI, rows_processed is for ALL previous fetches)
	** We need a cumulative total in c->cumul_rows_fetched
	*/
	*rows_processed = c->cumul_rows_fetched + rows_in_last_fetch;
	c->cumul_rows_fetched = *rows_processed;

	debug2( "%d rows fetch (cumul %ld)", rows_in_last_fetch, c->cumul_rows_fetched );

    /* Translate geometry columns from SqlServer . */
    if ( c->defined_geometries != NULL && rows_in_last_fetch > 0 )
    {
        if ( rows_in_last_fetch > ODBCDR_MAX_ARRAY_SIZE )
        {
	//		char buffer[256];
	//		sprintf(buffer, "TOO MANY GEOMETRY ROWS: %d (max is %d)", rows_in_last_fetch, ODBCDR_MAX_ARRAY_SIZE);
	//		msg_issue(buffer, 'e');
            goto the_exit;
        }

        /* Reduce array size to exactly that which is populated. */
        ODBCDR_RDBI_ERR( odbcdr_geom_setNumRows( context, c, rows_in_last_fetch ) );

        ODBCDR_RDBI_ERR( odbcdr_geom_convertDefinedFromSqlServer(context, c, rows_in_last_fetch));

    }   /* end if geometries */

    /* Convert blob columns into byte arrays. */
    if ( c->defined_blobs != NULL && rows_in_last_fetch > 0 )
    {
        if ( rows_in_last_fetch > ODBCDR_MAX_ARRAY_SIZE )
        {
            goto the_exit;
        }

        /* Reduce array size to exactly that which is populated. */
        ODBCDR_RDBI_ERR( odbcdr_blob_setNumRows( context, c, rows_in_last_fetch ) );

        ODBCDR_RDBI_ERR( odbcdr_blob_convertBlobsToByteArray(context, c, rows_in_last_fetch));

    }   /* end if geometries */

the_exit:
debug_area() odbcdr_show_context( context, c );
	debug_return(NULL, rdbi_status );
}
예제 #21
0
int local_rdbi_sql(
	rdbi_context_def *context,
    int     sqlid,
    rdbi_string_def* sql,
    int     defer,
    int type )
{


    rdbi_cursor_def *cursor     = (rdbi_cursor_def *) NULL; /* for ease of reference            */
    rdbi_cursor_def *cursor_coc = (rdbi_cursor_def *) NULL; /* for ease of reference            */
    int             trace_line_num = 0;
    int             sqlid_coc   = -1;

	char			stats[128];

#ifdef _DEBUG
    if (context->dispatch.capabilities.supports_unicode == 1){
        debug_on4("rdbi_sql2", "\tContext: %d Db: %s#%d\n\tSQL: %.120ls",
            sqlid, context->rdbi_cnct->db_name, context->rdbi_cnct->connect_id, sql->cwString);
    }else{
        debug_on4("rdbi_sql2", "\tContext: %d Db: %s#%d\n\tSQL: %.120s",
            sqlid, context->rdbi_cnct->db_name, context->rdbi_cnct->connect_id, sql->ccString);
    }
#endif

    cursor = context->rdbi_cursor_ptrs[sqlid];

    if (context->rdbi_cnct->autocommit_on && cursor->tran_begun) {
        char    tran_id[50];
        sprintf(tran_id, "auto-exec-%s %d", cursor->verb, cursor->trace_line);
        rdbi_tran_end(context, tran_id);
        cursor->tran_begun = FALSE;
    }

	sprintf(stats, "Open Cursor: %d", sqlid);
	debug_trace(stats, (wchar_t *)NULL, NULL);
    if (context->dispatch.capabilities.supports_unicode == 1)
	    debug_trace(NULL, sql->wString, &trace_line_num);
    else
        debug_trace(sql->cString, NULL, &trace_line_num);

    cursor->sql_parsed      = FALSE;    /* set default cursor conditions */
    cursor->bound_vars      = FALSE;
    cursor->defined_vars    = FALSE;
    cursor->sel_for_update  = FALSE;
    cursor->n_executions    = 0;
    cursor->tran_begun      = FALSE;
    cursor->trace_line      = trace_line_num;

#ifdef _DEBUG
	/* free any previously-stored SQL statement             */
	ut_vm_free("rdbi_sql", cursor->sql);
    cursor->sql = (char *)NULL;
 
  	if( sql->cwString )
  	{
        if (context->dispatch.capabilities.supports_unicode == 1)
        {
            cursor->sqlW = (wchar_t*)ut_vm_malloc("rdbi_sql", (wcslen(sql->cwString) + 1)*sizeof(wchar_t));
  		    if (cursor->sqlW == (wchar_t *)NULL) {
  			    cursor->status = RDBI_MALLOC_FAILED;
  			    goto the_exit;
  		    }
  		    wcscpy(cursor->sqlW, sql->cwString);
        }
        else
        {
  		    cursor->sql = (char*)ut_vm_malloc("rdbi_sql", strlen(sql->ccString) + 1);
  		    if (cursor->sql == (char *)NULL) {
  			    cursor->status = RDBI_MALLOC_FAILED;
  			    goto the_exit;
  		    }
  		    strcpy(cursor->sql, sql->ccString);
        }
	}
#endif

    /* instead of parsing the statement for 'current of cursor' we just do this: */
    cursor->status = RDBI_SUCCESS;
    cursor->statement_type = 0;
    cursor->sel_for_update = 0;

    /* get the verb */
	if (context->dispatch.capabilities.supports_unicode == 1)
    {
        local_parseW (sql->cwString, cursor->verb, type);
		cursor->status = (*(context->dispatch.sqlW))(context->drvr, cursor->vendor_data, sql->cwString, defer,
                                cursor->verb, NULL, cursor_coc == (rdbi_cursor_def *) NULL ?
                                (char *) NULL : cursor_coc->vendor_data);
    }
    else
    {
		local_parse (sql->ccString, cursor->verb, type);
		cursor->status = (*(context->dispatch.sql))(context->drvr, cursor->vendor_data, sql->ccString, defer,
                                cursor->verb, NULL, cursor_coc == (rdbi_cursor_def *) NULL ?
                                (char *) NULL : cursor_coc->vendor_data);
    }

    if (cursor->status == RDBI_SUCCESS)
        cursor->sql_parsed =    TRUE;

#ifdef _DEBUG
the_exit:
#endif
    context->rdbi_last_status = cursor->status;

    debug_return(NULL, cursor->status);
}
예제 #22
0
static int
get_blobSqlServer(
	odbcdr_context_def		*context,
    odbcdr_cursor_def       *cursor,
    int                     position,
    int                     blobNo,
    int                     recNo,
    int                     blobValid,
    pByteArray_def          *visionBlob_O,
	pByteArray_def		    *l_visionBlob_0
    )
{
    odbcdr_connData_def	    *connData = NULL;
    int                     rdbi_status = RDBI_GENERIC_ERROR;
    PBYTE                   pData = NULL;
    BYTE                    test[1];
    pByteArray_def          wkb = NULL;
    SQLLEN                  count;
    SQLRETURN               rc;

    debug_on( "odbcdr_blob:blob_convertFromSqlServer_S" );

    // Bound arrays offset 
    int offset = blobNo * ODBCDR_MAX_ARRAY_SIZE + recNo;

    if ( blobValid )
    {
        if ( cursor->odbcdr_blobNI[offset] == SQL_NULL_DATA || cursor->odbcdr_blobNI[offset] == 0)
        {
            *visionBlob_O = NULL;
            *l_visionBlob_0 = NULL;
            debug0( "Blob is NULL." );
            rdbi_status = RDBI_SUCCESS;
            goto the_exit;
        }

        debug0( "Blob is not NULL." );

        pData = (PBYTE)&cursor->odbcdr_blob[offset * ODBCDR_UBLOB_CHUNK_SIZE];
     
        count = cursor->odbcdr_blobNI[offset];
    }
    else
    {
        // Fetch as blob. First get the size.
        rc = SQLGetData( cursor->hStmt, 
                                     position, 
                                     SQL_C_BINARY, 
                                     test, 
                                     0, 
                                     &count);

        if ( rc != SQL_SUCCESS_WITH_INFO ) {
            ODBCDR_ODBC_ERR( rc,  
                             SQL_HANDLE_STMT, cursor->hStmt,
                            "SQLGetData", "getData");
        }
        
        if ( count <= 0 ) 
        {
            *visionBlob_O = NULL;
            *l_visionBlob_0 = NULL;
            debug0( "Blob is NULL." );
            rdbi_status = RDBI_SUCCESS;
            goto the_exit;
        }

        debug0( "Blob is not NULL." );

        // Allocate the buffer
        int  allocMore = true;
        if ( cursor->odbcdr_blob_tmp == NULL )
            cursor->odbcdr_blob_tmp = (PBYTE)malloc( count );
        else if ( cursor->odbcdr_blob_tmp_size < count )
            cursor->odbcdr_blob_tmp = (PBYTE)realloc( cursor->odbcdr_blob_tmp, count );
        else
            allocMore = false;

        if ( allocMore )
            cursor->odbcdr_blob_tmp_size = (int) count;

        pData = cursor->odbcdr_blob_tmp;

        SQLLEN lenOrIndex;
        ODBCDR_ODBC_ERR( SQLGetData( cursor->hStmt, 
                                        position, 
                                        SQL_C_BINARY, 
                                        pData,
                                        count, 
                                        &lenOrIndex),
                            SQL_HANDLE_STMT, cursor->hStmt,
                            "SQLGetData", "getData");
        cursor->odbcdr_blobNI[offset] = lenOrIndex;
    }

    // Create a byte array from the array of bytes. Note 'count' is an initial size.
    if ( NULL == ( wkb = IByteArray_Create( pData, (int) count) ) )
        goto the_exit;

    *visionBlob_O = *l_visionBlob_0 = wkb;

    rdbi_status = RDBI_SUCCESS;

  the_exit:
    debug_return( NULL, rdbi_status );
}
예제 #23
0
파일: debug.c 프로젝트: prophile/dim3
void debug_dump(void)
{
	int					i,idx,cnt,mem_sz;
	obj_type			*obj;
	effect_type			*effect;
	proj_type			*proj;
	weapon_type			*weap;
	proj_setup_type		*proj_setup;
	model_type			*mdl;
	script_type			*script;
	timer_type			*timer;
	SDL_version			*sdl_ver;
	
	console_add_system("Debugging info dumped to stdout");
	
	fprintf(stdout,"\n\n");
	fprintf(stdout,"#########################################################################\n");
	fprintf(stdout,"Dump: dim3 Debugging Info\n");
	fprintf(stdout,"Engine v%s\n",dim3_version);
	fprintf(stdout,"(c) 2000-2007 Klink! Software\n");
	fprintf(stdout,"#########################################################################\n\n");

		// game info
		
	fprintf(stdout,"**************************************\n");
	fprintf(stdout,"Game\n");
	fprintf(stdout,"**************************************\n\n");
	fprintf(stdout,"Project:  %s\n",net_setup.host.proj_name);
	fprintf(stdout,"Tick: %d\n",game_time_get());
	
	debug_return();
	
		// system info
		
	fprintf(stdout,"**************************************\n");
	fprintf(stdout,"System\n");
	fprintf(stdout,"**************************************\n\n");
	fprintf(stdout,"Arch Type: %s\n",arch_type);

#ifdef D3_OS_MAC
	fprintf(stdout,"OS Version: %d.%d.%d\n",os_vers_major,os_vers_minor_1,os_vers_minor_2);
#endif
	
	sdl_ver=(SDL_version*)SDL_Linked_Version();
	fprintf(stdout,"SDL Version: %d.%d.%d\n",sdl_ver->major,sdl_ver->minor,sdl_ver->patch);
	fprintf(stdout,"JavaScript Version: %.2f\n",((float)JS_VERSION/100.0f));
	fprintf(stdout,"PNG Version: %s\n",PNG_LIBPNG_VER_STRING);
	
	debug_return();
	
		// video info
		
	fprintf(stdout,"**************************************\n");
	fprintf(stdout,"Video\n");
	fprintf(stdout,"**************************************\n\n");
	fprintf(stdout,"Engine: %s\n",render_info.name);
	fprintf(stdout,"Screen: %d,%d at %d\n",render_info.monitor_x_sz,render_info.monitor_y_sz,render_info.monitor_refresh_rate);
	fprintf(stdout,"Max Texture Units: %d\n",render_info.texture_unit_count);
	fprintf(stdout,"Max Texture Size: %d\n",render_info.texture_max_size);
	
	if (!gl_check_frame_buffer_ok()) fprintf(stdout,"Shadow support disabled; Unsupported on this video card.\n");
	if (!gl_check_fsaa_ok()) fprintf(stdout,"FSAA support disabled; Unsupported on this video card.\n");
	if (!gl_check_texture_compress_ok()) fprintf(stdout,"Compression disabled; Unsupported on this video card.\n");
	if (!gl_check_point_sprite_ok()) fprintf(stdout,"Point sprite support disabled; Unsupported on this video card.\n");
	if (!gl_check_shader_ok()) fprintf(stdout,"GLSL support disabled; Unsupported on this video card.\n");

	fprintf(stdout,"Extensions:\n%s\n",render_info.ext_string);

#ifdef D3_OS_WINDOWS
	fprintf(stdout,"WGL Extensions:\n%s\n",wglGetExtensionsStringARB(wglGetCurrentDC()));
#endif
	
	debug_return();

		// map info
		
	fprintf(stdout,"**************************************\n");
	fprintf(stdout,"Map\n");
	fprintf(stdout,"**************************************\n\n");
	fprintf(stdout,"Map:  %s\n",map.info.name);
	fprintf(stdout,"Author:  %s\n",map.info.author);
	fprintf(stdout,"Mesh Count:  %d\n",map.mesh.nmesh);
	fprintf(stdout,"Liquid Count:  %d\n",map.liquid.nliquid);
	fprintf(stdout,"Spot Count:  %d\n",map.nspot);
	fprintf(stdout,"Scenery Count:  %d\n",map.nscenery);
	fprintf(stdout,"Node Count:  %d\n",map.nnode);
	
	debug_return();
	
		// objects

	debug_header("Objects",server.count.obj,(sizeof(obj_type)*server.count.obj));
	
	debug_space("Name",25);
	debug_space("Type",15);
	debug_space("Script",25);
	debug_space("Binding",10);
	debug_return();
	debug_space("------------------------",25);
	debug_space("------------------------",15);
	debug_space("------------------------",25);
	debug_space("---------",10);
	debug_return();
	
	obj=server.objs;
	
	for ((i=0);(i!=server.count.obj);i++) {
		debug_space(obj->name,25);
		debug_space(obj->type,15);
		if (!obj->scenery.on) {
			idx=scripts_find_uid(obj->attach.script_uid);
			debug_space(js.scripts[idx].name,25);
		}
		else {
			debug_space("*",25);
		}
		debug_space(bind_type_str[obj->bind],10);
		debug_return();
		obj++;
	}
	
	debug_return();
	
		// weapons

	debug_header("Weapons",server.count.weapon,(sizeof(weapon_type)*server.count.weapon));
	
	debug_space("Name",20);
	debug_space("Object",20);
	debug_return();
	debug_space("-------------------",20);
	debug_space("-------------------",20);
	debug_return();
	
	weap=server.weapons;
	
	for ((i=0);(i!=server.count.weapon);i++) {
		obj=object_find_uid(weap->obj_uid);
		
		debug_space(weap->name,20);
		debug_space(obj->name,20);
		debug_return();
		weap++;
	}
	
	debug_return();
	
		// projectile setups

	debug_header("Projectile Setups",server.count.proj_setup,(sizeof(proj_setup_type)*server.count.proj_setup));
	
	debug_space("Name",20);
	debug_space("Object",20);
	debug_space("Weapon",20);
	debug_return();
	debug_space("-------------------",20);
	debug_space("-------------------",20);
	debug_space("-------------------",20);
	debug_return();
	
	proj_setup=server.proj_setups;
	
	for ((i=0);(i!=server.count.proj_setup);i++) {
		obj=object_find_uid(proj_setup->obj_uid);
		weap=weapon_find_uid(proj_setup->weap_uid);
		
		debug_space(proj_setup->name,20);
		debug_space(obj->name,20);
		debug_space(weap->name,20);
		debug_return();
		proj_setup++;
	}
	
	debug_return();
	
		// models

	mem_sz=sizeof(model_type)*server.count.model;

	mdl=server.models;
	
	for (i=0;i!=server.count.model;i++) {
		mem_sz+=model_memory_size(mdl);
		mdl++;
	}
		
	debug_header("Models",server.count.model,mem_sz);
	
	debug_space("Name",32);
	debug_space("Vertexes",10);
	debug_space("Trigs",10);
	debug_space("Ref Count",10);
	debug_return();
	debug_space("------------------------------",32);
	debug_space("---------",10);
	debug_space("---------",10);
	debug_space("---------",10);
	debug_return();

	mdl=server.models;
	
	for (i=0;i!=server.count.model;i++) {
		debug_space(mdl->name,32);
		debug_int_space(mdl->meshes[0].nvertex,10);
		debug_int_space(mdl->meshes[0].ntrig,10);
		debug_int_space(mdl->reference_count,10);
		debug_return();
		mdl++;
	}
	
	debug_return();
	
		// projectiles
		
	debug_header("Projectiles",server.count.proj,(sizeof(proj_type)*max_projectile));
	
	debug_space("Name",20);
	debug_space("Object",20);
	debug_space("Weapon",20);
	debug_return();
	debug_space("-------------------",20);
	debug_space("-------------------",20);
	debug_space("-------------------",20);
	debug_return();
	
	proj=server.projs;
	
	for ((i=0);(i!=server.count.proj);i++) {
		obj=object_find_uid(proj->obj_uid);
		weap=weapon_find_uid(proj->weap_uid);
		proj_setup=proj_setups_find_uid(proj->proj_setup_uid);
		
		debug_space(proj_setup->name,20);
		debug_space(obj->name,20);
		debug_space(weap->name,20);
		debug_return();
		proj++;
	}
	
	debug_return();
	
		// effects
		
	debug_header("Effects",server.count.effect,(sizeof(effect_type)*max_effect));
	
	debug_space("Type",10);
	debug_space("Life Tick",10);
	debug_return();
	debug_space("---------",10);
	debug_space("---------",10);
	debug_return();
	
	effect=server.effects;
	
	for ((i=0);(i!=server.count.effect);i++) {
		debug_space(effect_type_str[effect->effecttype],10);
		debug_int_space(effect->life_tick,10);
		debug_return();
		effect++;
	}
	
	debug_return();
	
		// scripts
		
	script=js.scripts;
	
	cnt=0;
	for ((i=0);(i!=max_scripts);i++) {
		if (script->used) cnt++;
		script++;
	}
		
	debug_header("Scripts",cnt,-1);
	
	debug_space("Name",32);
	debug_return();
	debug_space("-------------------------------",32);
	debug_return();
	
	script=js.scripts;
	
	for ((i=0);(i!=max_scripts);i++) {
		if (script->used) {
			debug_space(script->name,32);
			debug_return();
		}
		script++;
	}
	
	debug_return();
	
		// timers
		
	debug_header("Timers",js.count.timer,-1);
	
	debug_space("Script",32);
	debug_space("Count",10);
	debug_space("Type",10);
	debug_return();
	debug_space("-------------------------------",32);
	debug_space("---------",10);
	debug_space("---------",10);
	debug_return();
	
	timer=js.timers;
	
	for ((i=0);(i!=js.count.timer);i++) {
		script=&js.scripts[scripts_find_uid(timer->attach.script_uid)];
		debug_space(script->name,32);
		debug_int_space(timer->count,10);
		debug_space((timer->mode==timer_mode_repeat)?"Timer":"Wait",10);
		debug_return();
		timer++;
	}
	
	debug_return();

	fflush(stdout);
}
예제 #24
0
int local_odbcdr_get_gen_id(
    odbcdr_context_def  *context,
	rdbi_string_def     *table_name_I,
	rdbiLong  *id_O
	)
{
	wchar_t				    sql_buf[100];
    rdbi_string_def         sqlval;
	int 				    rows;
	odbcdr_cursor_def	    *c = NULL;
	odbcdr_connData_def	    *connData;
    SQLLEN                  null_ind;
	int 				    rdbi_status = RDBI_GENERIC_ERROR;
	int						global_identity = ODBCDRV_STRING_EMPTY(table_name_I);
    ODBCDR_ERRORINFO_VARS;
    sqlval.wString = sql_buf;
    bool retLastAinc = (context->odbcdr_UseUnicode) ? (table_name_I->cwString == NULL || *table_name_I->cwString == '\0')
        : (table_name_I->cString == NULL || *table_name_I->cString == '\0');
#ifdef _DEBUG
    if (context->odbcdr_UseUnicode){
        debug_on1("odbcdr_get_gen_id", "table_name '%ls'", ISNULL(table_name_I->cwString));
    }else{
        debug_on1("odbcdr_get_gen_id", "table_name '%s'", ISNULL(table_name_I->ccString));
    }
#endif

    *id_O = 0;
	
	ODBCDR_RDBI_ERR( odbcdr_get_curr_conn( context, &connData ) );

	/* establish cursor. Reuse the existing one */
	if ( global_identity || retLastAinc) {
		
		/* set output value to one set by most recent insert statement execution */
		*id_O = context->odbcdr_last_autoincrement;

	} else {

		ODBCDR_RDBI_ERR( odbcdr_est_cursor(context, (char **)&c) );

        if (context->odbcdr_UseUnicode)
            odbcdr_swprintf(sqlval.wString, 100, L"select IDENT_CURRENT('%ls')", table_name_I->cwString);
        else
            sprintf(sqlval.cString, "select IDENT_CURRENT('%s')", table_name_I->ccString);

		ODBCDR_RDBI_ERR( local_odbcdr_sql( context, (char *)c, &sqlval, FALSE, (char *)NULL,
									(void *)NULL, (char *) NULL) );

		/* define output locations */
		ODBCDR_RDBI_ERR( odbcdr_define( context, (char *)c, "1", RDBI_LONG, sizeof(long),
										(char *) id_O, (SQLLEN *)&null_ind) );

		/* execute the SQL statement */
		ODBCDR_RDBI_ERR( odbcdr_execute( context, (char *)c, 1, 0, &rows) );

		/* execute the SQL statement & fetch row */
		ODBCDR_RDBI_ERR( odbcdr_fetch( context, (char *)c, 1, &rows) );

		/* Note: it returns null_ind set if no value was generated during this session */
	}

    rdbi_status = RDBI_SUCCESS;

the_exit:
	
/*	if ( !global_identity && c != (odbcdr_cursor_def *)NULL) {   */
	if ( c != (odbcdr_cursor_def *)NULL) {   
	    ODBCDR_ERRORINFO_GET;
	    odbcdr_fre_cursor (context, (char **)&c);
	    ODBCDR_ERRORINFO_SET;
	}

	debug_return(NULL, rdbi_status);
}
예제 #25
0
int odbcdr_blob_convertBlobsToByteArray(odbcdr_context_def *context, odbcdr_cursor_def *cursor, int num_rows)
{
    odbcdr_blob_col_list_def* columnList = cursor->defined_blobs;
    int rdbi_status = RDBI_GENERIC_ERROR;

    if (num_rows < 1 || columnList == NULL)
        goto the_exit;

    for (long i = 0;  i < columnList->size;  i++ )
    {
        long                 j;
        odbcdr_blob_def     **sqlserverBlob;
        odbcdr_blobNI_def   **sqlserverBlobNI;
        pByteArray_def      *visionBlob;
		pByteArray_def      *l_visionBlob;   
        odbcdr_blob_col_def  *column;

        column = col_list_getColumnByIndex_blob_S( columnList, i );
        if ( column == NULL || column->blob_list.size < num_rows )
            goto the_exit;

        sqlserverBlob = (odbcdr_blob_def **)ut_da_get( &column->blob_list, 0L );
        sqlserverBlobNI = (odbcdr_blobNI_def **)ut_da_get( &column->blobNI_list, 0L );
        visionBlob = column->address;
        l_visionBlob = column->l_address;

        if ( sqlserverBlob == NULL || sqlserverBlobNI == NULL || visionBlob == NULL ) goto the_exit;

        // Process each blob in the dataset. The blob are bound.
        // In case a large blob is hit (data truncation), the blobs are unbound and 
        // the current blob is fetched again as a blob.
        // After the entire batch is processed the blobs are bound again.
        int  unbound = false; 
        int wantedDim = -1;

        for ( j = 0;  j < num_rows;  j++ )
        {
            debug2( "converting blob column pos '%d', row %d",
                    column->position, j );

            IByteArray_Release(visionBlob[j]);
            visionBlob[j] = NULL;
            l_visionBlob[j] = NULL;

            // Check the status of this blob.
            int blobValid = blob_checkFetchStatusRow_S( cursor, i, j );

            // Unbind if not already unbound.
            if ( !blobValid && !unbound)
            {
                ODBCDR_ODBC_ERR( SQLBindCol( cursor->hStmt,
	                        (SQLUSMALLINT) column->position,
	                        (SQLSMALLINT) SQL_C_BINARY,
                            (SQLPOINTER) (char*)NULL,
                            (SQLINTEGER) 0,
	                        (SQLLEN *) NULL),
                    SQL_HANDLE_STMT, cursor->hStmt,
                    "SQLBindCol", "unbind" );  

                debug0("UNBOUND!\n");
                unbound = true;
            }

            if ( unbound )
            {
                // Advance 
		        ODBCDR_ODBC_ERR( SQLSetPos(	cursor->hStmt,
									        (SQLUSMALLINT) j+1, // Row # is 1 based
									        SQL_POSITION,
									        SQL_LOCK_NO_CHANGE),
								         SQL_HANDLE_STMT,cursor->hStmt,
						                 "SQLSetPos", "set position");
            }

		    /* Remember the last blob fetched in order to be released when the cursor is freed*/
            ODBCDR_RDBI_ERR( get_blobSqlServer( context, 
                                                      cursor,
                                                      column->position,
                                                      i,
                                                      j,
                                                      blobValid,
                                                      &visionBlob[j],
												      &l_visionBlob[j] ));
        }

        // Rebind back if the case.            
        if (unbound)
        {
            int offset = i * ODBCDR_MAX_ARRAY_SIZE;
            ODBCDR_ODBC_ERR( SQLBindCol( cursor->hStmt,
			            (SQLUSMALLINT) column->position,
			            (SQLSMALLINT) SQL_C_BINARY,
                        (SQLPOINTER) (char *)&cursor->odbcdr_blob[offset * ODBCDR_UBLOB_CHUNK_SIZE],
                        (SQLINTEGER) ODBCDR_UBLOB_CHUNK_SIZE,
			            (SQLLEN *) (char *)&cursor->odbcdr_blobNI[offset]),
	            SQL_HANDLE_STMT, cursor->hStmt,
	            "SQLBindCol", "rebind" );   
        }   
    }
	
    rdbi_status = RDBI_SUCCESS;

  the_exit:
    debug_return( NULL, rdbi_status );
}