int CppSQLite3Statement::execDML() { checkDB(); checkVM(); const char* szError=0; int nRet = sqlite3_step(mpVM); if (nRet == SQLITE_DONE) { int nRowsChanged = sqlite3_changes(mpDB); nRet = sqlite3_reset(mpVM); if (nRet != SQLITE_OK) { szError = sqlite3_errmsg(mpDB); IwError((szError)); } return nRowsChanged; } else { nRet = sqlite3_reset(mpVM); szError = sqlite3_errmsg(mpDB); IwError((szError)); return 0; } }
static int CreateInputWindow() { HWND hWnd; WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hbrBackground = NULL; wcex.hCursor = NULL; wcex.hIcon = NULL; wcex.hIconSm = NULL; wcex.hInstance = (HINSTANCE)GetModuleHandle(NULL); wcex.lpfnWndProc = WindowProc_InputOnly; wcex.lpszClassName = WC_INPUTFRAME; wcex.lpszMenuName = NULL; wcex.style = 0; if(!RegisterClassEx(&wcex)) { IwError(("RegisterClassEx() failed!")); return -1; } // // Create window // hWnd = CreateWindow( WC_INPUTFRAME, TEXT("Joystick using Raw Input API"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, HWND_MESSAGE, NULL, wcex.hInstance, NULL); if (hWnd == NULL) { IwError(("CreateWindow() failed!")); return -1; } IwDebugTraceLinePrintf("%s: Successfully created input message hidden window hWnd=0x%X, hInstance=0x%X\n", __FUNCTION__, hWnd, wcex.hInstance); return 0; }
void CppSQLite3Statement::checkDB() { if (mpDB == 0) { IwError(("Database not open")); } }
void Sys_Error (const char *error, ...) { va_list argptr; char string[1024]; // change stdin to non blocking // fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY); va_start (argptr,error); vsprintf (string,error,argptr); va_end (argptr); #ifdef USE_PMPEVENT PMPERROR(("Error: %s\n", string)); #else IwError(("%s", string)); fprintf(stderr, "Error: %s\n", string); #endif Host_Shutdown (); #ifdef USE_PMPEVENT PMPERROR(("Sys_Error - exiting.")); #else printf("Sys_Error - exiting.\n"); #endif exit (1); }
void CppSQLite3Table::checkResults() { if (mpaszResults == 0) { IwError(("Null Results pointer")); } }
void CppSQLite3DB::checkDB() { if (!mpDB) { IwError(("Database not open")); } }
void CppSQLite3Query::checkVM() { if (mpVM == 0) { IwError(("Null Virtual Machine pointer")); } }
CppSQLite3Query CppSQLite3Statement::execQuery() { checkDB(); checkVM(); int nRet = sqlite3_step(mpVM); if (nRet == SQLITE_DONE) { // no rows return CppSQLite3Query(mpDB, mpVM, true/*eof*/, false); } else if (nRet == SQLITE_ROW) { // at least 1 row return CppSQLite3Query(mpDB, mpVM, false/*eof*/, false); } else { nRet = sqlite3_reset(mpVM); const char* szError = sqlite3_errmsg(mpDB); IwError((szError)); return CppSQLite3Query(); } }
CppSQLite3Query CppSQLite3DB::execQuery(const char* szSQL) { checkDB(); sqlite3_stmt* pVM = compile(szSQL); int nRet = sqlite3_step(pVM); if (nRet == SQLITE_DONE) { // no rows return CppSQLite3Query(mpDB, pVM, true/*eof*/); } else if (nRet == SQLITE_ROW) { // at least 1 row return CppSQLite3Query(mpDB, pVM, false/*eof*/); } else { nRet = sqlite3_finalize(pVM); const char* szError= sqlite3_errmsg(mpDB); IwError((szError)); return CppSQLite3Query(); } }
s3eResult s3eHidControllerInit_platform() { CreateInputWindow(); HRESULT hr = DirectDrawCreateEx( NULL, (LPVOID *)&idd7, IID_IDirectDraw7, NULL ); if (hr != DD_OK) { IwError(("Couldn't initialize DirectDraw() :( ErrCode=0x%X\n", (uint32)hr)); } return S3E_RESULT_SUCCESS; }
void CppSQLite3Statement::bindNull(int nParam) { checkVM(); int nRes = sqlite3_bind_null(mpVM, nParam); if (nRes != SQLITE_OK) { IwError(("Error binding NULL param")); } }
void CppSQLite3Statement::bind(int nParam, const char* szValue) { checkVM(); int nRes = sqlite3_bind_text(mpVM, nParam, szValue, -1, SQLITE_TRANSIENT); if (nRes != SQLITE_OK) { IwError(("Error binding string param")); } }
void CppSQLite3Statement::bind(int nParam, const int nValue) { checkVM(); int nRes = sqlite3_bind_int(mpVM, nParam, nValue); if (nRes != SQLITE_OK) { IwError(("Error binding int param")); } }
void CppSQLite3Statement::bind(int nParam, const double dValue) { checkVM(); int nRes = sqlite3_bind_double(mpVM, nParam, dValue); if (nRes != SQLITE_OK) { IwError(("Error binding double param")); } }
const char* CppSQLite3Query::fieldName(int nCol) { checkVM(); if (nCol < 0 || nCol > mnCols-1) { IwError(("Invalid field index requested")); } return sqlite3_column_name(mpVM, nCol); }
const char* CppSQLite3Query::fieldValue(int nField) { checkVM(); if (nField < 0 || nField > mnCols-1) { IwError(("Invalid field index requested")); } return (const char*)sqlite3_column_text(mpVM, nField); }
int CppSQLite3DB::execScalar(const char* szSQL) { CppSQLite3Query q = execQuery(szSQL); if (q.eof() || q.numFields() < 1) { IwError(("Invalid scalar query")); } return atoi(q.fieldValue(0)); }
int CppSQLite3Query::fieldDataType(int nCol) { checkVM(); if (nCol < 0 || nCol > mnCols-1) { IwError(("Invalid field index requested")); } return sqlite3_column_type(mpVM, nCol); }
void CppSQLite3Statement::bind(int nParam, const unsigned char* blobValue, int nLen) { checkVM(); int nRes = sqlite3_bind_blob(mpVM, nParam, (const void*)blobValue, nLen, SQLITE_TRANSIENT); if (nRes != SQLITE_OK) { IwError(("Error binding blob param")); } }
void CppSQLite3Table::setRow(int nRow) { checkResults(); if (nRow < 0 || nRow > mnRows-1) { IwError(("Invalid row index requested")); } mnCurrentRow = nRow; }
const char* CppSQLite3Table::fieldName(int nCol) { checkResults(); if (nCol < 0 || nCol > mnCols-1) { IwError(("Invalid field index requested")); } return mpaszResults[nCol]; }
const unsigned char* CppSQLite3Query::getBlobField(int nField, int& nLen) { checkVM(); if (nField < 0 || nField > mnCols-1) { IwError(("Invalid field index requested")); } nLen = sqlite3_column_bytes(mpVM, nField); return (const unsigned char*)sqlite3_column_blob(mpVM, nField); }
const char* CppSQLite3Table::fieldValue(int nField) { checkResults(); if (nField < 0 || nField > mnCols-1) { IwError(("Invalid field index requested")); } int nIndex = (mnCurrentRow*mnCols) + mnCols + nField; return mpaszResults[nIndex]; }
void CppSQLite3DB::open(const char* szFile) { int nRet = sqlite3_open(szFile, &mpDB); if (nRet != SQLITE_OK) { const char* szError = sqlite3_errmsg(mpDB); IwError((szError)); } setBusyTimeout(mnBusyTimeoutMs); }
void CppSQLite3Statement::reset() { if (mpVM) { int nRet = sqlite3_reset(mpVM); if (nRet != SQLITE_OK) { const char* szError = sqlite3_errmsg(mpDB); IwError((szError)); } } }
void CppSQLite3Query::finalize() { if (mpVM && mbOwnVM) { int nRet = sqlite3_finalize(mpVM); mpVM = 0; if (nRet != SQLITE_OK) { const char* szError = sqlite3_errmsg(mpDB); IwError((szError)); } } }
sqlite3_stmt* CppSQLite3DB::compile(const char* szSQL) { checkDB(); char* szError=0; const char* szTail=0; sqlite3_stmt* pVM; int nRet = sqlite3_prepare(mpDB, szSQL, -1, &pVM, &szTail); if (nRet != SQLITE_OK) { IwError((szError)); } return pVM; }
void CppSQLite3Binary::setEncoded(const unsigned char* pBuf) { clear(); mnEncodedLen = strlen((const char*)pBuf); mnBufferLen = mnEncodedLen + 1; // Allow for NULL terminator mpBuf = (unsigned char*)malloc(mnBufferLen); if (!mpBuf) { IwError(("Cannot allocate memory")); } memcpy(mpBuf, pBuf, mnBufferLen); mbEncoded = true; }
const unsigned char* CppSQLite3Binary::getBinary() { if (mbEncoded) { // in/out buffers can be the same mnBinaryLen = sqlite3_decode_binary(mpBuf, mpBuf); if (mnBinaryLen == -1) { IwError(("Cannot decode binary")); } mbEncoded = false; } return mpBuf; }
int CppSQLite3DB::execDML(const char* szSQL) { checkDB(); char* szError=0; int nRet = sqlite3_exec(mpDB, szSQL, 0, 0, &szError); if (nRet == SQLITE_OK) { return sqlite3_changes(mpDB); } else { IwError((szError)); return 0; } }