/************************************************************************ * name: SQLDescribeColW * arguments: * returns/side-effects: * description: * NOTE: ************************************************************************/ ODBC_INTERFACE RETCODE SQL_API SQLDescribeColW (SQLHSTMT hstmt, SQLUSMALLINT column, SQLWCHAR *name, SQLSMALLINT name_max, SQLSMALLINT *name_len, SQLSMALLINT *type, SQLULEN *size, SQLSMALLINT *scale, SQLSMALLINT *nullable) { RETCODE ret = ODBC_ERROR; SQLCHAR *name_buffer = NULL; SQLSMALLINT name_buffer_len=0; ODBC_STATEMENT* stmt_handle = (ODBC_STATEMENT *) hstmt; OutputDebugString ("SQLDescribeColW called.\n"); name_buffer = UT_ALLOC (name_max); if (name_buffer == NULL && name_max > 0) { odbc_set_diag (stmt_handle->diag, "HY001", 0, "malloc failed"); return ODBC_ERROR; } memset (name_buffer, 0 , name_max); ret = SQLDescribeCol(hstmt, column, name_buffer, name_max, &name_buffer_len, type, size, scale, nullable); if (ret == ODBC_ERROR) { UT_FREE (name_buffer); return ret; } bytes_to_wide_char (name_buffer, name_buffer_len, &name, name_max, (int*)name_len, NULL); UT_FREE (name_buffer); return ret; }
/************************************************************************ * name: SQLGetDescRecW * arguments: * returns/side-effects: * description: * NOTE: ************************************************************************/ ODBC_INTERFACE RETCODE SQL_API SQLGetDescRecW (SQLHDESC hdesc, SQLSMALLINT record, SQLWCHAR *name, SQLSMALLINT name_max, SQLSMALLINT *name_len, SQLSMALLINT *type, SQLSMALLINT *subtype, SQLLEN *length, SQLSMALLINT *precision, SQLSMALLINT *scale, SQLSMALLINT *nullable) { RETCODE ret = ODBC_ERROR; SQLCHAR *name_buffer = NULL; SQLSMALLINT name_buffer_len=0; ODBC_DESC * desc_handle = hdesc; OutputDebugString ("SQLDescribeColW called.\n"); name_buffer = UT_ALLOC (name_max); if (name_buffer == NULL && name_max > 0) { odbc_set_diag (desc_handle->diag, "HY001", 0, "malloc failed"); return ODBC_ERROR; } memset (name_buffer, 0 , name_max); ret = SQLGetDescRec(hdesc, record, name_buffer, name_max, &name_buffer_len, type, subtype, length, precision, scale, nullable); if (ret == ODBC_ERROR) { UT_FREE (name_buffer); return ret; } bytes_to_wide_char (name_buffer, name_buffer_len, &name, name_max, (int*)name_len, NULL); UT_FREE (name_buffer); return ret; }
/************************************************************************ * name: SQLGetDescFieldW * arguments: * returns/side-effects: * description: * NOTE: ************************************************************************/ ODBC_INTERFACE RETCODE SQL_API SQLGetDescFieldW (SQLHDESC hdesc, SQLSMALLINT record, SQLSMALLINT field, SQLPOINTER value, SQLINTEGER value_max, SQLINTEGER *value_len) { RETCODE ret = ODBC_ERROR; char* cb_value = NULL; int cb_value_len = 0; ODBC_DESC *DescriptorHandle = (ODBC_DESC*)hdesc; OutputDebugString ("SQLGetDescFieldW called.\n"); cb_value = UT_ALLOC (value_max); if (cb_value == NULL && value_max > 0) { odbc_set_diag (DescriptorHandle->diag, "HY001", 0, "malloc failed"); return ODBC_ERROR; } memset (cb_value, 0 , value_max); SQLGetDescField(hdesc, record, field, cb_value, value_max, &cb_value_len); if (ret == ODBC_ERROR) { UT_FREE (cb_value); return ret; } bytes_to_wide_char (cb_value, cb_value_len, (wchar_t**)&value, value_max, (int*)value_len, NULL); UT_FREE (cb_value); return ret; }
/************************************************************************ * name: SQLColumnsW * arguments: * returns/side-effects: * description: * NOTE: ************************************************************************/ ODBC_INTERFACE RETCODE SQL_API SQLColumnsW (SQLHSTMT hstmt, SQLWCHAR *catalog, SQLSMALLINT catalog_len, SQLWCHAR *schema, SQLSMALLINT schema_len, SQLWCHAR *table, SQLSMALLINT table_len, SQLWCHAR *column, SQLSMALLINT column_len) { RETCODE ret = ODBC_ERROR; char *cb_catalog = NULL, *cb_schema = NULL, *cb_table = NULL, *cb_column = NULL; int cb_catalog_len = 0, cb_schema_len = 0, cb_table_len = 0, cb_column_len = 0; ODBC_STATEMENT* stmt_handle = (ODBC_STATEMENT *) hstmt; OutputDebugString ("SQLColumnsW called.\n"); wide_char_to_bytes (catalog, catalog_len, &cb_catalog, &cb_catalog_len, stmt_handle->conn->charset); wide_char_to_bytes (schema, schema_len, &cb_schema, &cb_schema_len, stmt_handle->conn->charset); wide_char_to_bytes (table, table_len, &cb_table, &cb_table_len, stmt_handle->conn->charset); wide_char_to_bytes (column, column_len, &cb_column, &cb_column_len, stmt_handle->conn->charset); ret = SQLColumns (hstmt, cb_catalog, cb_catalog_len, cb_schema, cb_schema_len, cb_table, cb_table_len, cb_column, cb_column_len); UT_FREE (cb_catalog); UT_FREE (cb_schema); UT_FREE (cb_table); UT_FREE (cb_column); return ret; }
/************************************************************************ * name: SQLTablesW * arguments: * returns/side-effects: * description: * NOTE: ************************************************************************/ ODBC_INTERFACE RETCODE SQL_API SQLTablesW (SQLHSTMT hstmt, SQLWCHAR *catalog, SQLSMALLINT catalog_len, SQLWCHAR *schema, SQLSMALLINT schema_len, SQLWCHAR *table, SQLSMALLINT table_len, SQLWCHAR *type, SQLSMALLINT type_len) { RETCODE ret = ODBC_ERROR; SQLCHAR *cb_catalog = NULL, *cb_schema = NULL, *cb_table = NULL, *cb_type=NULL; int cb_catalog_len = 0, cb_schema_len = 0, cb_table_len = 0, cb_type_len = 0; OutputDebugString ("SQLTablesW called.\n"); wide_char_to_bytes (catalog, catalog_len, &cb_catalog, &cb_catalog_len, NULL); wide_char_to_bytes (schema, schema_len, &cb_schema, &cb_schema_len, NULL); wide_char_to_bytes (table, table_len, &cb_table, &cb_table_len, NULL); wide_char_to_bytes (type, type_len, &cb_type, &cb_type_len, NULL); ret = SQLTables(hstmt, cb_catalog, cb_catalog_len, cb_schema, cb_schema_len, cb_table, cb_table_len, cb_type, cb_type_len); UT_FREE(cb_catalog); UT_FREE(cb_schema); UT_FREE(cb_table); UT_FREE(cb_type); return ret; }
/************************************************************************ * name: SQLGetCursorNameW * arguments: * returns/side-effects: * description: * NOTE: ************************************************************************/ ODBC_INTERFACE RETCODE SQL_API SQLGetCursorNameW (SQLHSTMT hstmt, SQLWCHAR *cursor, SQLSMALLINT cursor_max, SQLSMALLINT *cursor_len) { RETCODE ret = ODBC_ERROR; char* cursor_name = NULL; SQLSMALLINT cursor_name_len = 0; ODBC_STATEMENT* stmt_handle = (ODBC_STATEMENT *) hstmt; OutputDebugString ("SQLGetCursorNameW called.\n"); cursor_name = UT_ALLOC (cursor_max); if (cursor_name == NULL && cursor_max > 0) { odbc_set_diag (stmt_handle->diag, "HY001", 0, "malloc failed"); return ODBC_ERROR; } memset (cursor_name, 0 , cursor_max); ret = SQLGetCursorName(hstmt, cursor_name, cursor_max, &cursor_name_len); if (ret == ODBC_ERROR) { UT_FREE (cursor_name); return ret; } bytes_to_wide_char (cursor_name, cursor_name_len, &cursor, cursor_max, (int*)cursor_len, NULL); UT_FREE(cursor_name); return ret; }
/************************************************************************ * name: SQLNativeSqlW * arguments: * returns/side-effects: * description: * NOTE: ************************************************************************/ ODBC_INTERFACE RETCODE SQL_API SQLNativeSqlW (SQLHDBC hdbc, SQLWCHAR *in, SQLINTEGER in_len, SQLWCHAR *out, SQLINTEGER out_max, SQLINTEGER *out_len) { RETCODE ret = ODBC_ERROR; SQLCHAR *sql_state, *sql_text_buffer = NULL; int sql_state_len; ODBC_CONNECTION * ConnectionHandle = (ODBC_CONNECTION *) hdbc; OutputDebugString ("SQLNativeSqlW called.\n"); ret = wide_char_to_bytes (in, in_len, &sql_state, &sql_state_len, NULL); sql_text_buffer = UT_ALLOC (out_max); if (sql_text_buffer == NULL && out_max > 0) { odbc_set_diag (ConnectionHandle->diag, "HY001", 0, "malloc failed"); return ODBC_ERROR; } memset (sql_text_buffer, 0 , out_max); ret = SQLNativeSql(hdbc, sql_state, sql_state_len, sql_text_buffer, out_max, out_len); if (ret == ODBC_ERROR) { UT_FREE (sql_text_buffer); return ret; } bytes_to_wide_char (sql_state, sql_state_len, &out, out_max, out_len, NULL); UT_FREE (sql_text_buffer); return ret; }
/************************************************************************ * name: SQLConnectW * arguments: * returns/side-effects: * description: * NOTE: ************************************************************************/ ODBC_INTERFACE RETCODE SQL_API SQLConnectW (SQLHDBC hdbc, SQLWCHAR *dsn, SQLSMALLINT dsn_len, SQLWCHAR *user, SQLSMALLINT user_len, SQLWCHAR *auth, SQLSMALLINT auth_len) { SQLCHAR *cb_user, *cb_auth, *cb_dsn; int cb_user_len, cb_auth_len, cb_dsn_len; RETCODE ret; OutputDebugString ("SQLConnectW called\n"); wide_char_to_bytes (user, user_len, &cb_user, &cb_user_len, NULL); wide_char_to_bytes (auth, auth_len, &cb_auth, &cb_auth_len, NULL); wide_char_to_bytes (dsn, dsn_len, &cb_dsn, &cb_dsn_len, NULL); ret = SQLConnect (hdbc, cb_dsn, cb_dsn_len, cb_user, cb_user_len, cb_auth, cb_auth_len) ; UT_FREE (cb_user); UT_FREE (cb_auth); UT_FREE (cb_dsn); return ret; }
/************************************************************************ * name: SQLGetDiagRecW * arguments: * returns/side-effects: * description: * NOTE: ************************************************************************/ ODBC_INTERFACE RETCODE SQL_API SQLGetDiagRecW (SQLSMALLINT HandleType, SQLHANDLE Handle, SQLSMALLINT RecNumber, SQLWCHAR * Sqlstate, SQLINTEGER * NativeError, SQLWCHAR * MessageText, SQLSMALLINT BufferLength, SQLSMALLINT * TextLength) { SQLCHAR *sql_state, *message_text_buffer = NULL; int sql_state_len = 0; SQLSMALLINT message_text_buffer_len = 0; RETCODE ret; ODBC_ENV *env; env = (ODBC_ENV *) Handle; OutputDebugString ("SQLGetDiagRecW called\n"); wide_char_to_bytes (Sqlstate, sqlwcharlen (Sqlstate), &sql_state, &sql_state_len, NULL); message_text_buffer = UT_ALLOC (BufferLength); if (message_text_buffer == NULL && BufferLength > 0) { odbc_set_diag (env->diag, "HY001", 0, "malloc failed"); return ODBC_ERROR; } memset (message_text_buffer, 0 , BufferLength); ret = SQLGetDiagRec (HandleType, Handle, RecNumber, sql_state, NativeError, message_text_buffer, BufferLength, &message_text_buffer_len); if (ret == ODBC_ERROR) { UT_FREE (message_text_buffer); return ret; } bytes_to_wide_char (message_text_buffer, message_text_buffer_len, &MessageText, BufferLength, (int*)TextLength, NULL); UT_FREE (message_text_buffer); return ret; }
/************************************************************************ * name: SQLDriverConnectW * arguments: * returns/side-effects: * description: * NOTE: ************************************************************************/ ODBC_INTERFACE RETCODE SQL_API SQLDriverConnectW (SQLHDBC hdbc, SQLHWND hwnd, SQLWCHAR *in, SQLSMALLINT in_len, SQLWCHAR *out, SQLSMALLINT out_max, SQLSMALLINT *out_len, SQLUSMALLINT completion) { RETCODE rc = ODBC_SUCCESS; SQLCHAR *pt_in, *pt_out; int encode_len = 0, temp_out_len = 0; ODBC_CONNECTION* conn = (ODBC_CONNECTION*)hdbc; OutputDebugString ("SQLDriverConnectW called\n"); rc = wide_char_to_bytes (in, in_len, &pt_in, &encode_len, NULL); if (rc != ODBC_SUCCESS) { odbc_set_diag (conn->diag, "HY001", 0, "encode failed"); return ODBC_ERROR; } pt_out = UT_ALLOC (out_max); if (pt_out == NULL && out_max > 0) { odbc_set_diag (conn->diag, "HY001", 0, "malloc failed"); return ODBC_ERROR; } memset (pt_out, 0, out_max); rc = SQLDriverConnect ( hdbc, hwnd, pt_in, in_len, pt_out, out_max, out_len, completion); if (out) { bytes_to_wide_char (pt_out, strlen (pt_out), &out, out_max, &temp_out_len, NULL); } if (out_len) { *out_len = temp_out_len; } UT_FREE (pt_in); UT_FREE (pt_out); return rc; }
/************************************************************************ * name: SQLSetCursorNameW * arguments: * returns/side-effects: * description: * NOTE: ************************************************************************/ ODBC_INTERFACE RETCODE SQL_API SQLSetCursorNameW (SQLHSTMT hstmt, SQLWCHAR *name, SQLSMALLINT name_len) { RETCODE ret = ODBC_ERROR; SQLCHAR *cb_name = NULL; int cb_name_len = 0; OutputDebugString ("SQLSetCursorNameW called.\n"); wide_char_to_bytes (name, name_len, &cb_name, &cb_name_len, NULL); ret = SQLSetCursorName(hstmt, cb_name, cb_name_len); UT_FREE(cb_name); return ret; }
/************************************************************************ * name: SQLPrepareW * arguments: * returns/side-effects: * description: * NOTE: ************************************************************************/ ODBC_INTERFACE RETCODE SQL_API SQLPrepareW (SQLHSTMT hstmt, SQLWCHAR *str, SQLINTEGER str_len) { RETCODE ret = ODBC_ERROR; char* sql_state = NULL; int sql_state_len = 0; OutputDebugString ("SQLPrepareW called.\n"); wide_char_to_bytes (str, str_len, &sql_state, &sql_state_len, NULL); ret = SQLPrepare(hstmt, sql_state, sql_state_len); UT_FREE(sql_state); return ret; }
/************************************************************************ * name: SQLExecDirectW * arguments: * returns/side-effects: * description: * NOTE: ************************************************************************/ ODBC_INTERFACE RETCODE SQL_API SQLExecDirectW (SQLHSTMT StatementHandle, SQLWCHAR * StatementText, SQLINTEGER TextLength) { SQLCHAR *sql_text; RETCODE ret; int sql_len = 0; wide_char_to_bytes (StatementText, TextLength, &sql_text, &sql_len, NULL); OutputDebugString ("SQLExecDirectW called\n"); ret = SQLExecDirect (StatementHandle, sql_text, sql_len); UT_FREE (sql_text); return ret; }
/************************************************************************ * name: odbc_free_record * arguments: * returns/side-effects: * description: * NOTE: ************************************************************************/ PUBLIC RETCODE odbc_free_record (ODBC_RECORD * record) { ODBC_RECORD *r, *prev; if (record == NULL) { goto error; } NA_FREE (record->base_column_name); NA_FREE (record->base_table_name); NA_FREE (record->catalog_name); NA_FREE (record->literal_prefix); NA_FREE (record->literal_suffix); NA_FREE (record->local_type_name); NA_FREE (record->name); NA_FREE (record->schema_name); NA_FREE (record->table_name); NA_FREE (record->type_name); // remove link from descriptor if (record->desc != NULL) { for (r = record->desc->records, prev = NULL; r != NULL && r != record; r = r->next) { prev = r; } if (r == record) { if (prev != NULL) prev->next = record->next; else record->desc->records = record->next; } } UT_FREE (record); return ODBC_SUCCESS; error: return ODBC_ERROR; }
/************************************************************************ * name: odbc_free_desc * arguments: * returns/side-effects: * description: * NOTE: * desc->con이 null이 아니면 con에 연결된 explicit desc로 간주한다. ************************************************************************/ PUBLIC RETCODE odbc_free_desc (ODBC_DESC * desc) { ODBC_DESC *d, *prev; if (desc == NULL) { goto error; } // for explicit, remove link with connection handle if (desc->conn != NULL) { for (d = desc->conn->descriptors, prev = NULL; d != NULL && d != desc; d = d->next) { prev = d; } if (d == desc) { if (prev != NULL) prev->next = desc->next; else desc->conn->descriptors = desc->next; } } odbc_free_all_records (desc->records); desc->records = NULL; odbc_free_diag (desc->diag, FREE_ALL); desc->diag = NULL; UT_FREE (desc); return ODBC_SUCCESS; error: return ODBC_ERROR; }
PUBLIC RETCODE odbc_free_env (ODBC_ENV * env) { ODBC_ENV *e, *prev; if (env->conn != NULL) { /* HY010 - DM */ odbc_set_diag (env->diag, "HY010", 0, NULL); return ODBC_ERROR; } /* remove from list */ for (e = odbc_environments, prev = NULL; e != NULL && e != env; e = e->next) { prev = e; } if (e == env) { if (prev != NULL) { prev->next = env->next; } else { odbc_environments = env->next; } } odbc_free_diag (env->diag, FREE_ALL); env->diag = NULL; NC_FREE (env->program_name); UT_FREE (env); return ODBC_SUCCESS; }
/************************************************************************ * name: SQLForeignKeysW * arguments: * returns/side-effects: * description: * NOTE: ************************************************************************/ ODBC_INTERFACE RETCODE SQL_API SQLForeignKeysW (SQLHSTMT hstmt, SQLWCHAR *pk_catalog, SQLSMALLINT pk_catalog_len, SQLWCHAR *pk_schema, SQLSMALLINT pk_schema_len, SQLWCHAR *pk_table, SQLSMALLINT pk_table_len, SQLWCHAR *fk_catalog, SQLSMALLINT fk_catalog_len, SQLWCHAR *fk_schema, SQLSMALLINT fk_schema_len, SQLWCHAR *fk_table, SQLSMALLINT fk_table_len) { RETCODE ret = ODBC_ERROR; char *cb_pk_catalog = NULL, *cb_pk_schema = NULL, *cb_pk_table = NULL, *cb_fk_catalog = NULL, *cb_fk_schema = NULL, *cb_fk_table = NULL; int cb_pk_catalog_len = 0, cb_pk_schema_len = 0, cb_pk_table_len = 0, cb_fk_catalog_len = 0, cb_fk_schema_len = 0, cb_fk_table_len = 0; OutputDebugString ("SQLForeignKeysW called.\n"); wide_char_to_bytes (pk_catalog, pk_catalog_len, &cb_pk_catalog, &cb_pk_catalog_len, NULL); wide_char_to_bytes (pk_schema, pk_schema_len, &cb_pk_schema, &cb_pk_schema_len, NULL); wide_char_to_bytes (pk_table, pk_table_len, &cb_pk_table, &cb_pk_table_len, NULL); wide_char_to_bytes (fk_catalog, fk_catalog_len, &cb_fk_catalog, &cb_fk_catalog_len, NULL); wide_char_to_bytes (fk_schema, fk_schema_len, &cb_fk_schema, &cb_fk_schema_len, NULL); wide_char_to_bytes (fk_table, fk_table_len, &cb_fk_table, &cb_fk_table_len, NULL); ret = SQLForeignKeys(hstmt, cb_pk_catalog, cb_pk_catalog_len, cb_pk_schema, cb_pk_schema_len, cb_pk_table, cb_pk_table_len, cb_fk_catalog, cb_fk_catalog_len, cb_fk_schema, cb_fk_schema_len, cb_fk_table, cb_fk_table_len); UT_FREE(cb_pk_catalog); UT_FREE(cb_pk_schema); UT_FREE(cb_pk_table); UT_FREE(cb_fk_catalog); UT_FREE(cb_fk_schema); UT_FREE(cb_fk_table); return ret; }