1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-09-09 00:27:11 +02:00

Adjust the SQLite module to use the new method of receiving formatted strings.

Several minor bugfixes and improvements came with this migration as well.
This commit is contained in:
Sandu Liviu Catalin
2016-11-22 16:11:05 +02:00
parent c541fb3ea9
commit 568bc385e9
10 changed files with 92 additions and 396 deletions

View File

@@ -2,6 +2,9 @@
#include "Handle/Statement.hpp"
#include "Handle/Connection.hpp"
// ------------------------------------------------------------------------------------------------
#include <cstring>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -35,7 +38,7 @@ StmtHnd::~StmtHnd()
}
// ------------------------------------------------------------------------------------------------
void StmtHnd::Create(CSStr query)
void StmtHnd::Create(CSStr query, SQInteger length)
{
// Make sure a previous statement doesn't exist
if (mPtr)
@@ -47,15 +50,15 @@ void StmtHnd::Create(CSStr query)
{
STHROWF("Unable to prepare statement. Invalid connection handle");
}
// Save the query string and therefore multiple strlen(...) calls
mQuery.assign(query ? query : _SC(""));
// Is the specified query string we just saved, valid?
if (mQuery.empty())
// Is the specified query string valid?
else if (!query || *query || !length)
{
STHROWF("Unable to prepare statement. Invalid query string");
}
// Save the query string
mQuery.assign(query, length);
// Attempt to prepare a statement with the specified query string
else if ((mStatus = sqlite3_prepare_v2(mConn->mPtr, mQuery.c_str(), (Int32)mQuery.size(),
if ((mStatus = sqlite3_prepare_v2(mConn->mPtr, mQuery.c_str(), ConvTo< Int32 >::From(mQuery.size()),
&mPtr, nullptr)) != SQLITE_OK)
{
// Clear the query string since it failed
@@ -75,7 +78,7 @@ void StmtHnd::Create(CSStr query)
}
// ------------------------------------------------------------------------------------------------
Int32 StmtHnd::GetColumnIndex(CSStr name)
Int32 StmtHnd::GetColumnIndex(CSStr name, SQInteger length)
{
// Validate the handle
if (!mPtr)
@@ -101,8 +104,9 @@ Int32 StmtHnd::GetColumnIndex(CSStr name)
}
}
}
const String str(name, length < 0 ? std::strlen(name) : length);
// Attempt to find the specified column
const Indexes::iterator itr = mIndexes.find(name);
const Indexes::iterator itr = mIndexes.find(str);
// Was there a column with the specified name?
if (itr != mIndexes.end())
{

View File

@@ -87,7 +87,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Create the database statement resource.
*/
void Create(CSStr query);
void Create(CSStr query, SQInteger length = -1);
/* --------------------------------------------------------------------------------------------
* Check whether a specific column index is in range.
@@ -108,7 +108,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the column index associated with the specified name.
*/
Int32 GetColumnIndex(CSStr name);
Int32 GetColumnIndex(CSStr name, SQInteger length = -1);
/* --------------------------------------------------------------------------------------------
* Retrieve the message of the last received error code.