/************************************************************************ * 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: 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: 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: 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; }
void display_windows_ce_infos (void) { Uint32 i; char *param; WCHAR wparam[PARAMAX_LEN + 1]; OSVERSIONINFO vinfo; static const char *action_names[] = { "SPI_GETPLATFORMMANUFACTURER", "SPI_GETPLATFORMNAME", "SPI_GETPLATFORMTYPE" }; static const Uint32 actions[] = { SPI_GETPLATFORMMANUFACTURER, SPI_GETPLATFORMNAME, SPI_GETPLATFORMTYPE }; for (i = 0; i < sizeof (actions) / sizeof (Uint32); i++) { if (SystemParametersInfo (actions[i], PARAMAX_LEN, wparam, 0) == FALSE) { LOG_ERR ("SystemParametersInfo(%s) " "failed (error %i)", action_names[i], GetLastError ()); continue; } param = wide_char_to_bytes (wparam, 0, CP_ACP); if (param == NULL) { continue; } LOG_INF ("%s %s", action_names[i], param); free_memory (param); } if (GetVersionEx (&vinfo) == FALSE) { LOG_ERR ("GetVersionEx() " "failed (error %i)", GetLastError ()); } else { if (vinfo.dwPlatformId != VER_PLATFORM_WIN32_CE) { LOG_ERR ("this system is not a Windows Embedded CE OS"); } else { LOG_INF ("Windows Mobile %i.%i", vinfo.dwMajorVersion, vinfo.dwMinorVersion); } } LOG_INF ("SM_CXSCREEN: %i; SM_CYSCREEN: %i", GetSystemMetrics (SM_CXSCREEN), GetSystemMetrics (SM_CYSCREEN)); }
/************************************************************************ * 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: 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: 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; }
/** * Locate a file under one of the data directories * @param name Name of file relative to data directory * @return Pointer to a malloc'd buffer containing the name under which the * file was found (free()-ing the buffer is the responsibility of the caller.) * or NULL if could not locate file (not found, or not enough memory, or the * name given was absolute) * @author Andre Majorel */ char * locate_data_file (const char *const name) { #if defined(_WIN32_WCE) wchar_t *filename; char *pathname; char c; Uint32 i, j; Uint32 len; if (wince_module_pathname == NULL) { len = MAX_PATH * sizeof (wchar_t); filename = (wchar_t *) memory_allocation (len); if (filename == NULL) { LOG_ERR ("not enough memory to allocate %i bytes", len); return NULL; } if (GetModuleFileName (NULL, filename, MAX_PATH) == 0) { LOG_ERR ("GetModuleFileName () failed!"); free_memory ((char *) filename); return NULL; } /* removes the application name in the pathname */ i = wcslen (filename) - 1; while (filename[i] != L'\\') { i--; } filename[i + 1] = 0; wince_module_pathname = wide_char_to_bytes (filename, 0, CP_ACP); if (wince_module_pathname == NULL) { LOG_ERR ("wide_char_to_bytes () failed!"); free_memory ((char *) filename); return NULL; } free_memory ((char *) filename); } len = strlen (wince_module_pathname) + strlen (name) + 1; pathname = memory_allocation (len); if (pathname == NULL) { LOG_ERR ("not enough memory to allocate %i bytes", len); return NULL; } strcpy (pathname, wince_module_pathname); j = strlen (pathname); for (i = 0; i < strlen (name); i++, j++) { c = name[i]; if (c == '/') { pathname[j] = '\\'; } else { pathname[j] = c; } } pathname[j] = 0; return pathname; #else static const char bogus = '\0'; static const char *home_dir; const char **p; char *pathname; #ifdef WIN32 struct _stat s; #else struct stat s; #endif #ifdef __EMSCRIPTEN__ const char *subdir = "/assets/"; #else const char *subdir = "/share/games/powermanga/"; #endif if (name == NULL) { LOG_ERR ("NULL pointer was passed as an argument!"); return NULL; } /* if absolute path, return a pointer to a duplicate string */ if (*name == '/') { return string_duplicate (name); } /* process each folder of the list */ for (p = data_directories;; p++) { if (*p == 0) { pathname = memory_allocation (strlen (prefix_dir) + strlen (subdir) + strlen (name) + 1); if (pathname == NULL) { fflush (stdout); LOG_ERR ("not enough memory"); return NULL; } strcpy (pathname, prefix_dir); strcat (pathname, subdir); strcat (pathname, name); } /* not user anymore */ else if (**p == '~') { home_dir = &bogus; if (home_dir == &bogus) { home_dir = getenv ("HOME"); } if (home_dir == 0) { /* $HOME not set. Skip this directory */ continue; } pathname = memory_allocation (strlen (home_dir) + 1 + strlen (*p + 1) + 1 + strlen (name) + 1); if (pathname == NULL) { fflush (stdout); LOG_ERR ("not enough memory"); return NULL; } strcpy (pathname, home_dir); strcat (pathname, *p + 1); strcat (pathname, "/"); strcat (pathname, name); } else { /* check if the file is located in current directory */ pathname = memory_allocation (strlen (*p) + 1 + strlen (name) + 1); if (pathname == NULL) { fflush (stdout); LOG_ERR ("not enough memory"); return NULL; } strcpy (pathname, *p); strcat (pathname, "/"); strcat (pathname, name); } #ifdef WIN32 if (_stat (pathname, &s) == 0 && !(s.st_mode & _S_IFDIR)) { return pathname; } #else if (stat (pathname, &s) == 0 && !S_ISDIR (s.st_mode)) { return pathname; } #endif free_memory (pathname); if (*p == 0) { break; } } /* not found */ return NULL; #endif }