コード例 #1
0
ファイル: CppSQLite3.cpp プロジェクト: cjm8374/JmPos
int CppSQLite3Query::fieldIndex(const char* szField)
{
	checkVM();

	if (szField)
	{
		for (int nField = 0; nField < mnCols; nField++)
		{
			const char* szTemp = sqlite3_column_name(mpVM, nField);

			if (strcmp(szField, szTemp) == 0)
			{
				return nField;
			}
		}
	}

	throw CppSQLite3Exception(CPPSQLITE_ERROR,
							"Invalid field name requested",
							DONT_DELETE_MSG);
}
コード例 #2
0
ファイル: CppSQLite3.cpp プロジェクト: cjm8374/JmPos
CppSQLite3Table CppSQLite3DB::getTable(const char* szSQL)
{
	checkDB();

	char* szError=0;
	char** paszResults=0;
	int nRet;
	int nRows(0);
	int nCols(0);

	nRet = sqlite3_get_table(mpDB, szSQL, &paszResults, &nRows, &nCols, &szError);

	if (nRet == SQLITE_OK)
	{
		return CppSQLite3Table(paszResults, nRows, nCols);
	}
	else
	{
		throw CppSQLite3Exception(nRet, szError);
	}
}
コード例 #3
0
ファイル: CppSQLite3.cpp プロジェクト: CyberShadow/Ditto
int CppSQLite3DB::execDML(const TCHAR* szSQL)
{
	checkDB();

	sqlite3_stmt* pVM = compile(szSQL);

	int nRet = sqlite3_step(pVM);

	if (nRet == SQLITE_DONE)
	{
		nRet = sqlite3_changes(mpDB);
		sqlite3_finalize(pVM);
	}
	else
	{
		nRet = sqlite3_finalize(pVM);
		SQLITE3_ERRMSG(mpDB);
		throw CppSQLite3Exception(nRet, (TCHAR*)szError, DONT_DELETE_MSG);
	}
	
	return nRet;
}
コード例 #4
0
ファイル: CppSQLite3U.cpp プロジェクト: wolfspelz/Apollo
int CppSQLite3DB::execDML(LPCTSTR szSQL)
{
	int nRet;
	sqlite3_stmt* pVM; 
	checkDB();

	do{ 
		pVM = compile(szSQL);

		nRet = _sqlite3_step(pVM);
	
		if (nRet == SQLITE_ERROR)
		{
			LPCTSTR szError = (LPCTSTR) _sqlite3_errmsg(mpDB);
			throw CppSQLite3Exception(nRet, (LPTSTR)szError, DONT_DELETE_MSG);
		}
		nRet = _sqlite3_finalize(pVM);
	} 
	while( nRet == SQLITE_SCHEMA );

  return nRet; // hw was missing ?
}
コード例 #5
0
ファイル: CppSQLite3.cpp プロジェクト: fly2mars/suAgent
unsigned char* CppSQLite3Binary::allocBuffer(int nLen)
{
	clear();

	// Allow extra space for encoded binary as per comments in
	// SQLite encode.c See bottom of this file for implementation
	// of SQLite functions use 3 instead of 2 just to be sure ;-)
	mnBinaryLen = nLen;
	mnBufferLen = 3 + (257*nLen)/254;

	mpBuf = (unsigned char*)malloc(mnBufferLen);

	if (!mpBuf)
	{
		throw CppSQLite3Exception(CPPSQLITE_ERROR,
								"Cannot allocate memory",
								DONT_DELETE_MSG);
	}

	mbEncoded = false;

	return mpBuf;
}
コード例 #6
0
ファイル: CppSQLite3.cpp プロジェクト: CyberShadow/Ditto
void CppSQLite3Query::nextRow()
{
	checkVM();

	int nRet = sqlite3_step(mpVM);

	if (nRet == SQLITE_DONE)
	{
		// no rows
		mbEof = true;
	}
	else if (nRet == SQLITE_ROW)
	{
		// more rows, nothing to do
	}
	else
	{
		nRet = sqlite3_finalize(mpVM);
		mpVM = 0;
		SQLITE3_ERRMSG(mpDB);
		throw CppSQLite3Exception(nRet, (TCHAR*)szError, DONT_DELETE_MSG);
	}
}
コード例 #7
0
ファイル: CppSQLite3U.cpp プロジェクト: cspark777/PDFManager
void CppSQLite3Query::nextRow()
{
	checkVM();

	int nRet = _sqlite3_step(mpVM);

	if (nRet == SQLITE_DONE)
	{
		// no rows
		mbEof = true;
	}
	else if (nRet == SQLITE_ROW)
	{
		// more rows, nothing to do
	}
	else
	{
		nRet = _sqlite3_finalize(mpVM);
		mpVM = 0;
		LPCTSTR szError = (LPCTSTR)_sqlite3_errmsg(mpDB);
		throw CppSQLite3Exception(nRet,	(LPTSTR)szError, DONT_DELETE_MSG);
	}
}
コード例 #8
0
void CppSQLite3Query::NextRow()
{
	CheckStmt();

	int nRet = sqlite3_step(mpStmt);

	if (nRet == SQLITE_DONE)
	{
		// no rows  
		mbEof = true;
	}
	else if (nRet == SQLITE_ROW)
	{
		// more rows, nothing to do  
	}
	else
	{
		nRet = sqlite3_finalize(mpStmt);
		mpStmt = 0;
		const char* szError = sqlite3_errmsg(mpDB);
		throw CppSQLite3Exception(nRet, szError, DONT_DELETE_MSG);
	}
}
コード例 #9
0
void CppSQLite3Query::nextRow()
{
	checkVM();

	int nRet = sqlite3_step(mpVM);

	if (nRet == SQLITE_DONE)
	{
		// no rows
		mbEof = true;
	}
	else if (nRet == SQLITE_ROW)
	{
		// more rows, nothing to do
	}
	else
	{
		nRet = sqlite3_finalize(mpVM);
		mpVM = 0;
        const char* szError = sqlite3_errmsg(mpDB);
        throw CppSQLite3Exception(nRet, szError);
	}
}
コード例 #10
0
ファイル: CppSQLite3.cpp プロジェクト: fly2mars/suAgent
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);
		throw CppSQLite3Exception(nRet, (char*)szError, DONT_DELETE_MSG);
	}
}
コード例 #11
0
ファイル: CppSQLite3.cpp プロジェクト: hgl888/TeamTalk
int CppSQLite3Statement::bindParameterIndex(const char* szParam)
{
    checkVM();

    int nParam = sqlite3_bind_parameter_index(mpVM, szParam);

    /*int nn =*/ sqlite3_bind_parameter_count(mpVM);
    /*const char* sz1 =*/ sqlite3_bind_parameter_name(mpVM, 1);
    /*const char* sz2 =*/ sqlite3_bind_parameter_name(mpVM, 2);

    if (!nParam)
    {
        char buf[128];
        #if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__)
            sprintf_s(buf, 128, "Parameter '%s' is not valid for this statement", szParam);
        #else
            sprintf(buf, "Parameter '%s' is not valid for this statement", szParam);
        #endif

        throw CppSQLite3Exception(CPPSQLITE_ERROR, buf, DONT_DELETE_MSG);
    }

    return nParam;
}
コード例 #12
0
ファイル: CppSQLite3U.cpp プロジェクト: cspark777/PDFManager
void CppSQLite3Statement::checkVM()
{
	if (mpVM == 0)
		throw CppSQLite3Exception(CPPSQLITE_ERROR,_T("Null Virtual Machine pointer"), DONT_DELETE_MSG);
}
コード例 #13
0
ファイル: CppSQLite3U.cpp プロジェクト: cspark777/PDFManager
void CppSQLite3Statement::checkDB()
{
	if (mpDB == 0) throw CppSQLite3Exception(CPPSQLITE_ERROR,_T("Database not open"), DONT_DELETE_MSG);
}
コード例 #14
0
ファイル: CppSQLite3U.cpp プロジェクト: cspark777/PDFManager
void CppSQLite3DB::checkDB()
{
	if (!mpDB)
		throw CppSQLite3Exception(CPPSQLITE_ERROR,_T("Database not open"), DONT_DELETE_MSG);
	
}