static debug_area *dview_alloc(running_machine &machine, debug_view_type type) { debug_area *dv; dv = global_alloc(debug_area(machine, type)); return dv; }
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 ); }
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 ); }