Exemplo n.º 1
0
static JSVAL sqlite_column_bytes16(JSARGS args) {
    HandleScope scope;
    Local<External>wrap = Local<External>::Cast(args[0]);
    sqlite3_stmt *stmt = (sqlite3_stmt *)wrap->Value();
    int iCol = args[1]->IntegerValue();
    return scope.Close(Integer::New(sqlite3_column_bytes16(stmt, iCol)));
}
/**
Reads a record from security policies table.

@param aStmtHandle Statement handle. It cannot be NULL.
@param aSecurityPolicy Security policies container.
@param aObjType Output parameter, will be initialized with the database object type: KDefaultObjType,
				KDbObjType, RSqlSecurityPolicy::ETable.
@param aObjName Output parameter, database object name (for example, table name), which is protected by the
				current security policy.
@param aPolicyType Output parameter, will be initialized with the database policy type: RSqlSecurityPolicy::EReadPolicy,
				   RSqlSecurityPolicy::EWritePolicy, RSqlSecurityPolicy::ESchemaPolicy.
@return The created security policy object.

@leave KErrGeneral, invalid security policy data;
	   KErrNoMemory, Out of memory.
*/
TSecurityPolicy TSqlDbSysSettings::ReadCurrSecurityPolicyL(sqlite3_stmt* aStmtHandle, TInt& aObjType, 
														   TPtrC& aObjName, TInt& aPolicyType)
	{
	__ASSERT_DEBUG(aStmtHandle != NULL, __SQLPANIC(ESqlPanicBadArgument));
	aObjType = sqlite3_column_int(aStmtHandle, KObjTypeColIdx);
    //The "ObjectName" column type might be different than SQLITE_TEXT - malformed database.
    if(sqlite3_column_type(aStmtHandle, KObjNameColIdx) != SQLITE_TEXT)
        {
        __SQLLEAVE(KErrGeneral);   
        }
    const void* text = sqlite3_column_text16(aStmtHandle, KObjNameColIdx);
    //Null column value - this might be an indication of an "out of memory" problem, if the column text  
    //is in UTF8 format. (sqlite3_column_text16() may allocate memory for UTF8->UTF16 conversion)
    __SQLLEAVE_IF_NULL(const_cast<void*>(text));
	TInt len = (TUint)sqlite3_column_bytes16(aStmtHandle, KObjNameColIdx) / sizeof(TUint16);
	aObjName.Set(reinterpret_cast <const TUint16*> (text), len);
	aPolicyType = sqlite3_column_int(aStmtHandle, KObjPolicyTypeColIdx);
	len = sqlite3_column_bytes(aStmtHandle, KObjPolicyDataColIdx);
	if(len != sizeof(TSecurityPolicy))
		{
		//Check if the error is "out of memory" (which may happen when retrieving text column data
		//and the column encoding is different, in which case  the column text has to be converted 
		//and a new block of memory has to be allocated for the conversion).
		TInt err2 = ::StmtReset(aStmtHandle);
		__SQLLEAVE(err2 == KErrNoMemory ? KErrNoMemory : KErrGeneral);
		}
	const void* data = sqlite3_column_blob(aStmtHandle, KObjPolicyDataColIdx);
	TSecurityPolicy policy;
	policy.Set(TPtrC8(reinterpret_cast <const TUint8*> (data), len));
	return policy;
	}
Exemplo n.º 3
0
wxString CQueueStorage::Impl::GetColumnText(sqlite3_stmt* statement, int index, bool shrink)
{
	wxString ret;

#ifdef __WXMSW__
	(void)shrink;
	const wxChar* text = static_cast<const wxChar*>(sqlite3_column_text16(statement, index));
	if (text)
		ret = text;
#else
	const char* text = static_cast<const char*>(sqlite3_column_text16(statement, index));
	int len = sqlite3_column_bytes16(statement, index);
	if (text)
	{
		wxStringBuffer buffer(ret, len);
		wxChar* out = buffer;

		int outlen = utf16_.ToWChar( out, len, text, len );
		buffer[outlen] = 0;
	}
	if (shrink)
		ret.Shrink();
#endif

	return ret;
}
Exemplo n.º 4
0
String SQLiteStatement::getColumnText(int col)
{
    ASSERT(col >= 0);
    if (!m_statement)
        if (prepareAndStep() != SQLITE_ROW)
            return String();
    if (columnCount() <= col)
        return String();
    const UChar* string = reinterpret_cast<const UChar*>(sqlite3_column_text16(m_statement, col));
    return StringImpl::create8BitIfPossible(string, sqlite3_column_bytes16(m_statement, col) / sizeof(UChar));
}
Exemplo n.º 5
0
/*
* Class:     com_sabo_sqlite_SQLiteDatabase_SQLiteQuery
* Method:    nativeQuery
* Signature: (J)[Ljava/lang/String;
*/
JNIEXPORT jobjectArray JNICALL Java_com_sabo_sqlite_SQLiteDatabase_00024SQLiteQuery_nativeQuery
(JNIEnv *env, jobject clazz, jlong statementPtr) {
	sqlite3_stmt *pStmt;
	jobjectArray objArray;
	int nCol;
	int i;
	int rc;
	int nLen;
	jchar *zVal;

	jclass clazzString;
	jstring val;

	assert(statementPtr != 0);
	pStmt = (sqlite3_stmt *)statementPtr;
	nCol = sqlite3_column_count(pStmt);
	assert(nCol > 0);
	clazzString = env->FindClass("java/lang/String");
	assert(clazzString != NULL);
	/**
	  Ignore to check clazzString.
	*/
	if (nCol <= 0) throw_sqlite3_exception(env, "[SQLite]: nCol is less than 1.");
	objArray = env->NewObjectArray(nCol, clazzString, NULL);
	if (objArray == NULL) throw_sqlite3_exception(env, "[SQLite]: Allocate objArray failed (No enough memory)");
	rc = sqlite3_step(pStmt);	
	if (rc == SQLITE_ROW) {
		for (i = 0; i < nCol; ++i) {
			zVal = (jchar *)sqlite3_column_text16(pStmt, i);
			nLen = 0;
			if (zVal) {
				nLen = sqlite3_column_bytes16(pStmt, i);
				assert(nLen > 0);
			}
			if (nLen > 0) {
				val = env->NewString(zVal, nLen/sizeof(jchar));
				assert(val != NULL);
				if (val == NULL) throw_sqlite3_exception(env, "[SQLite]: NewString failed...");
			}
			else {
				val = NULL;
			}
			env->SetObjectArrayElement(objArray, i, val);
		}
	}
	else {
		if (rc == SQLITE_OK || rc == SQLITE_DONE) {
			return NULL;
		}
		throw_sqlite3_exception(env, "[SQLITE]: Fail to run sqltie3_step.");
	}

	return objArray;
}
static jstring nativeExecuteForString(JNIEnv* env, jclass clazz,
        jlong connectionPtr, jlong statementPtr) {
    SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
    sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr);

    int err = executeOneRowQuery(env, connection, statement);
    if (err == SQLITE_ROW && sqlite3_column_count(statement) >= 1) {
        const jchar* text = static_cast<const jchar*>(sqlite3_column_text16(statement, 0));
        if (text) {
            size_t length = sqlite3_column_bytes16(statement, 0) / sizeof(jchar);
            return env->NewString(text, length);
        }
    }
    return NULL;
}
Exemplo n.º 7
0
array<__wchar_t>^ zDBBinaryReader::ToChars(int offset, int length)
{
	int							cb;				// Local size information
	const wchar_t*				pwchData;		// Pointer into raw data
	array<__wchar_t>^			rg;				// Managed char array of data
	PinnedCharPtr				pinRg;			// Pinned pointer into rg[]
	int							cch;			// Unicode character count

	CHECK_DISPOSED(m_disposed);
	if(offset < 0) throw gcnew ArgumentException();
	if(length < 0) throw gcnew ArgumentException();
	if((offset % sizeof(wchar_t)) != 0) throw gcnew ArgumentException();
	if((length % sizeof(wchar_t)) != 0) throw gcnew ArgumentException();

	// When accessing things as Unicode character data, ask SQLite for a
	// specific size that will properly adjusted as necessary

	cb = sqlite3_column_bytes16(m_pStatement->Handle, m_ordinal);
	if((offset + length) > cb) throw gcnew ArgumentOutOfRangeException();

	// Special case: If the caller wants zero bytes, don't go pinning
	// pointers and copying nothing.  Just return what they want

	if(length == 0) return gcnew array<__wchar_t>(0);

	cch = length / sizeof(wchar_t);				// Calculate character count
	rg = gcnew array<__wchar_t>(cch);			// Create return array
	pinRg = &rg[0];								// Pin and get a pointer

	// Only copy the amount of data that the caller is looking for from
	// the SQLite buffer into the managed Char array buffer

	pwchData = reinterpret_cast<const wchar_t*>(sqlite3_column_text16(m_pStatement->Handle, m_ordinal));
	wmemcpy_s(pinRg, cch, pwchData + (offset / sizeof(wchar_t)), cch);
	return rg;
}
Exemplo n.º 8
0
std::wstring sqlite3_reader::getstring16(int index) {
	check_reader(index);
	return std::wstring((const wchar_t*)sqlite3_column_text16(this->cmd->stmt, index), sqlite3_column_bytes16(this->cmd->stmt, index)/2);
}
Exemplo n.º 9
0
bool QSpatiaLiteResultPrivate::fetchNext(QSqlCachedResult::ValueCache &values, int idx, bool initialFetch)
{
    int res;
    int i;

    if (skipRow) {
        // already fetched
        Q_ASSERT(!initialFetch);
        skipRow = false;
        for(int i=0;i<firstRow.count();i++)
            values[i]=firstRow[i];
        return skippedStatus;
    }
    skipRow = initialFetch;

    if(initialFetch) {
        firstRow.clear();
        firstRow.resize(sqlite3_column_count(stmt));
    }

    if (!stmt) {
        q->setLastError(QSqlError(QCoreApplication::translate("QSpatiaLiteResult", "Unable to fetch row"),
                                  QCoreApplication::translate("QSpatiaLiteResult", "No query"), QSqlError::ConnectionError));
        q->setAt(QSql::AfterLastRow);
        return false;
    }
    res = sqlite3_step(stmt);

    switch(res) {
    case SQLITE_ROW:
        // check to see if should fill out columns
        if (rInf.isEmpty())
            // must be first call.
            initColumns(false);
        if (idx < 0 && !initialFetch)
            return true;
        for (i = 0; i < rInf.count(); ++i) {
            switch (sqlite3_column_type(stmt, i)) {
            case SQLITE_BLOB:
                values[i + idx] = QByteArray(static_cast<const char *>(
                            sqlite3_column_blob(stmt, i)),
                            sqlite3_column_bytes(stmt, i));
                break;
            case SQLITE_INTEGER:
                values[i + idx] = sqlite3_column_int64(stmt, i);
                break;
            case SQLITE_FLOAT:
                switch(q->numericalPrecisionPolicy()) {
                    case QSql::LowPrecisionInt32:
                        values[i + idx] = sqlite3_column_int(stmt, i);
                        break;
                    case QSql::LowPrecisionInt64:
                        values[i + idx] = sqlite3_column_int64(stmt, i);
                        break;
                    case QSql::LowPrecisionDouble:
                    case QSql::HighPrecision:
                    default:
                        values[i + idx] = sqlite3_column_double(stmt, i);
                        break;
                };
                break;
            case SQLITE_NULL:
                values[i + idx] = QVariant(QVariant::String);
                break;
            default:
                values[i + idx] = QString(reinterpret_cast<const QChar *>(
                            sqlite3_column_text16(stmt, i)),
                            sqlite3_column_bytes16(stmt, i) / sizeof(QChar));
                break;
            }
        }
        return true;
    case SQLITE_DONE:
        if (rInf.isEmpty())
            // must be first call.
            initColumns(true);
        q->setAt(QSql::AfterLastRow);
        sqlite3_reset(stmt);
        return false;
    case SQLITE_CONSTRAINT:
    case SQLITE_ERROR:
        // SQLITE_ERROR is a generic error code and we must call sqlite3_reset()
        // to get the specific error message.
        res = sqlite3_reset(stmt);
        q->setLastError(qMakeError(access, QCoreApplication::translate("QSpatiaLiteResult",
                        "Unable to fetch row"), QSqlError::ConnectionError, res));
        q->setAt(QSql::AfterLastRow);
        return false;
    case SQLITE_MISUSE:
    case SQLITE_BUSY:
    default:
        // something wrong, don't get col info, but still return false
        q->setLastError(qMakeError(access, QCoreApplication::translate("QSpatiaLiteResult",
                        "Unable to fetch row"), QSqlError::ConnectionError, res));
        sqlite3_reset(stmt);
        q->setAt(QSql::AfterLastRow);
        return false;
    }
}
Exemplo n.º 10
0
int SQLiteSTMT::ColumnBytes16(int iCol) {
  return sqlite3_column_bytes16(handle, iCol);
}
Exemplo n.º 11
0
int Sql::column_bytes(sqlite3_stmt *pStmt,int iCol)
{
    return(sqlite3_column_bytes16(pStmt,iCol));
}
Exemplo n.º 12
0
	std::wstring sqlite3_cursor::getstring16(int index) {
		READER_CHECK(wstring);
		return std::wstring((const wchar_t*)sqlite3_column_text16(this->cmd->stmt, index), sqlite3_column_bytes16(this->cmd->stmt, index)/2);
	}
/* column bytes 16 */
int
sqlite_statement::column_bytes16 (
  int _index
){
return sqlite3_column_bytes16 (this->stmt, _index);
}
Exemplo n.º 14
0
__declspec(dllexport) int WINAPI sqlite3_column_bytes16_interop(sqlite3_stmt *stmt, int iCol)
{
  return sqlite3_column_bytes16(stmt, iCol);
}