예제 #1
0
inline CFStringRef SQLite3StatementCreateBindParameterNameWithIndex(SQLite3StatementRef statement, CFIndex index, bool withoutSpecialCharacter) {
  CFStringRef name = NULL;
  const char *name_ = sqlite3_bind_parameter_name(statement->stmt, (int)index);
  if (name_)
    name = CFStringCreateWithCString(statement->allocator, name_ + (int)withoutSpecialCharacter, kCFStringEncodingUTF8);
  return name;
}
예제 #2
0
ECode CStmt::BindParameterName(
    /* [in] */ Int32 pos,
    /* [out] */ String* str)
{
    VALIDATE_NOT_NULL(str);
#if HAVE_SQLITE3 && HAVE_SQLITE3_BIND_PARAMETER_NAME
    hvm *v = (hvm *)mHandle;

    if (v && v->vm && v->h) {
        Int32 npar = sqlite3_bind_parameter_count((sqlite3_stmt *) v->vm);
        const char *name = NULL;

        if (pos < 1 || pos > npar) {
            *str = String(NULL) ;
            return E_ILLEGAL_ARGUMENT_EXCEPTION;
        }
        name = sqlite3_bind_parameter_name((sqlite3_stmt *) v->vm, pos);
        if (name) {
            *str = String(name);
        }
    } else {
        return E_NULL_POINTER_EXCEPTION;
    }
#else
    return E_SQL_FEATURE_NOT_SUPPORTED_EXCEPTION;
#endif
    return NOERROR;
}
예제 #3
0
CAMLprim value caml_sqlite3_bind_parameter_name(value v_stmt, value v_index)
{
  CAMLparam1(v_stmt);
  sqlite3_stmt *stmt = safe_get_stmtw("bind_parameter_name", v_stmt)->stmt;
  int i = Int_val(v_index);
  range_check(i - 1, sqlite3_bind_parameter_count(stmt));
  CAMLreturn(Val_string_option(sqlite3_bind_parameter_name(stmt, i)));
}
예제 #4
0
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];
		sprintf(buf, "Parameter '%s' is not valid for this statement", szParam);
		throw CppSQLite3Exception(CPPSQLITE_ERROR, buf, DONT_DELETE_MSG);
	}

	return nParam;
}
SWIGEXPORT jstring JNICALL Java_com_almworks_sqlite4java__1SQLiteSwiggedJNI_sqlite3_1bind_1parameter_1name(JNIEnv *jenv, jclass jcls, jlong jarg1, jint jarg2) {
  jstring jresult = 0 ;
  sqlite3_stmt *arg1 = (sqlite3_stmt *) 0 ;
  int arg2 ;
  char *result = 0 ;
  
  (void)jenv;
  (void)jcls;
  arg1 = *(sqlite3_stmt **)&jarg1; 
  arg2 = (int)jarg2; 
  result = (char *)sqlite3_bind_parameter_name(arg1,arg2);
  if (result) jresult = (*jenv)->NewStringUTF(jenv, (const char *)result);
  return jresult;
}
예제 #6
0
static void objv_db_sqlite_bind_data(objv_zone_t * zone,sqlite3_stmt * stmt,objv_object_t * data, sqlite3_destructor_type type) {

    int c = sqlite3_bind_parameter_count(stmt);

    for(int i=1; i<=c; i++) {

        const char * name = sqlite3_bind_parameter_name(stmt, i);
        objv_object_t * key = NULL;
        objv_object_t * v;

        if(name) {
            key = (objv_object_t *) objv_string_new(zone, name);
        }
        else {
            key = (objv_object_t *) objv_string_new_format(zone, "@%d",i -1);
        }

        v = objv_object_objectValueForKey(data, key, NULL);

        if(v == NULL) {
            sqlite3_bind_null(stmt, i);
        }
        else if(objv_object_isKindOfClass(v, OBJV_CLASS(Value))) {
            {
                objv_value_t * value = (objv_value_t *) v;
                if(value->type == OBJV_TYPE(int)) {
                    sqlite3_bind_int(stmt, i, value->intValue);
                }
                else if(value->type == OBJV_TYPE(uint)) {
                    sqlite3_bind_int(stmt, i, value->uintValue);
                }
                else if(value->type == OBJV_TYPE(long)) {
                    sqlite3_bind_int64(stmt, i, value->longValue);
                }
                else if(value->type == OBJV_TYPE(ulong)) {
                    sqlite3_bind_int64(stmt, i, value->ulongValue);
                }
                else if(value->type == OBJV_TYPE(longLong)) {
                    sqlite3_bind_int64(stmt, i, value->longLongValue);
                }
                else if(value->type == OBJV_TYPE(ulongLong)) {
                    sqlite3_bind_int64(stmt, i, value->ulongLongValue);
                }
                else if(value->type == OBJV_TYPE(float)) {
                    sqlite3_bind_double(stmt, i, value->floatValue);
                }
                else if(value->type == OBJV_TYPE(double)) {
                    sqlite3_bind_double(stmt, i, value->doubleValue);
                }
                else if(value->type == OBJV_TYPE(boolean)) {
예제 #7
0
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;
}
예제 #8
0
파일: Database.cpp 프로젝트: noriter/nit
const char* Database::Query::getParamName(int paramIndex, bool goodName)
{
	if (_stmt == NULL) return NULL;

	const char* paramName = sqlite3_bind_parameter_name(_stmt, paramIndex);
	if (!goodName) return paramName;

	switch (paramName[0])
	{
	case '@' :	return paramName + 1;
	case '$' :	return paramName + 1;
	case ':' :	return paramName + 1;
	default:	return paramName;
	}
}
예제 #9
0
 void Statement::initParameters() {
     if (!_stmt) {
         return;
     }
     
     clearParameters();
     
     _parametersCount = sqlite3_bind_parameter_count(_stmt);
     if (_parametersCount <= 0) {
         return;
     }
     
     for (int i = 1; i <= _parametersCount; ++i) {
         const char *name = sqlite3_bind_parameter_name(_stmt, i);
         if (name && name[0]) {
             _nameParameters[name] = i;
         }
     }
 }
jstring JNICALL Java_com_baidu_javalite_PrepareStmt_sqlite3_1bind_1parameter_1name(
        JNIEnv *env, jclass cls, jlong handle, jint index)
{
  if (handle == 0)
  {
    throwSqliteException(env, "handle is NULL");
    return 0;
  }

  sqlite3_stmt* stmt = (sqlite3_stmt*) handle;

  const char* name = sqlite3_bind_parameter_name(stmt, index);

  if (name == 0)
  {
    return (*env)->NewStringUTF(env, "");
  } else
  {
    return (*env)->NewStringUTF(env, name);
  }
}
예제 #11
0
// doc: The sqlite3_bind_*() routines must be called after sqlite3_prepare() or sqlite3_reset() and before sqlite3_step().
//      Bindings are not cleared by the sqlite3_reset() routine. Unbound parameters are interpreted as NULL.
bool SqliteSetupBindings(JSContext *cx, sqlite3_stmt *pStmt, JS::HandleObject argObj, JS::HandleObject curObj) {

	JS::RootedValue val(cx);
	int anonParamIndex = 0;
	const char *name;

	int count = sqlite3_bind_parameter_count(pStmt);
	for ( int param = 1; param <= count; param++ ) { // The first host parameter has an index of 1, not 0.

		// doc: Parameters of the form "?" have no name. ... If the value n is out of range or if the n-th parameter is nameless, then NULL is returned.
		name = sqlite3_bind_parameter_name(pStmt, param);

		// doc: name is UTF-8 encoding

		if ( name == NULL ) {

			JL_CHKM(argObj, E_PARAM, E_NUM(anonParamIndex), E_DEFINED);
			JL_CHK( JL_GetElement(cx, argObj, anonParamIndex, &val) ); // works with {0:2,1:2,2:2,length:3} and [2,2,2]
			anonParamIndex++;
		} else
		if ( name[0] == '@' ) {

			JL_CHKM(argObj, E_PARAM, E_NAME(name), E_DEFINED);
			JL_CHK( JS_GetProperty(cx, argObj, name+1, &val) );
		} else
		if ( name[0] == ':' ) {
			
			JL_CHKM(curObj, E_PARAM, E_NAME(name), E_DEFINED);
			JL_CHK( JS_GetProperty(cx, curObj, name+1, &val) );
		} else {

			JL_ERR(E_PARAM, E_NOTSUPPORTED);
		}
		
		JL_CHK( jsvalToSqlite( cx, SqliteTargetBind( pStmt, param ), val ) );
	}
	return true;
	JL_BAD;
}
예제 #12
0
파일: core.c 프로젝트: ra-kalai/lem-sqlite3
static int
bindtable(lua_State *T, sqlite3_stmt *stmt)
{
	int parameters = sqlite3_bind_parameter_count(stmt);
	const char *name;
	const char *err;
	int i;

	for (i = 1; i <= parameters; i++) {
		int ret;

		name = sqlite3_bind_parameter_name(stmt, i);
		lua_settop(T, 2);
		if (name == NULL || name[0] == '?')
			lua_rawgeti(T, 2, i);
		else if (name[0] == '@')
			lua_getfield(T, 2, name + 1);
		else
			lua_getfield(T, 2, name);

		ret = _bind_arg(T, 3, stmt, i);

		if (ret != SQLITE_OK) {
			err = sqlite3_errmsg(sqlite3_db_handle(stmt));
			goto error;
		}
	}
	return 0;

error:
	(void)sqlite3_clear_bindings(stmt);
	luaL_where(T, 1);
	if (name == NULL || name[0] == '?')
		lua_pushfstring(T, "error binding %d: %s", i, err);
	else
		lua_pushfstring(T, "error binding '%s': %s", name, err);
	lua_concat(T, 2);
	return -1;
}
예제 #13
0
파일: Database.cpp 프로젝트: noriter/nit
void Database::Query::bindError(int paramIndex)
{
	if (_stmt == NULL)
		NIT_THROW_FMT(EX_INVALID_STATE, "can't bind : statement finalized");

	sqlite3* db = getSqlite3();
	if (db == NULL)
		NIT_THROW_FMT(EX_INVALID_STATE, "can't bind : database closed");

	// If any previous step() we should reset().
	if (_stepResult == SQLITE_ROW)
		sqlite3_reset(_stmt);

	const char* paramName = sqlite3_bind_parameter_name(_stmt, paramIndex);
	if (paramName)
	{
		NIT_THROW_FMT(EX_DATABASE, "can't bind '%s': %s", paramName, sqlite3_errmsg(db));
	}
	else
	{
		NIT_THROW_FMT(EX_DATABASE, "can't bind '?%d': %s", paramIndex, sqlite3_errmsg(db));
	}
}
예제 #14
0
void SQLiteCommand::prepareBindContext() {
	if (myBindContext.size() > 0) {
		return;
	}

	size_t number = 0;

	for (size_t i = 0; i < myStatements.size(); ++i) {
		sqlite3_stmt *statement = myStatements[i];
		const int count = sqlite3_bind_parameter_count(statement);
		for (int j = 1; j <= count; ++j) {
			++number;
			const char *name = sqlite3_bind_parameter_name(statement, j);
			if (name == 0) {
				myBindContext.push_back(BindParameter(number));
			} else {
				const std::string namestr(name);
				if (std::find_if(myBindContext.begin(), myBindContext.end(), BindParameterComparator(namestr)) == myBindContext.end()) {
					myBindContext.push_back(BindParameter(number, namestr));
				}
			}
		}
	}
}
예제 #15
0
String Database::Statement::parameterName(int parameter) const
{
	String name = sqlite3_bind_parameter_name(mStmt, parameter);
	return name.substr(1);
}
예제 #16
0
int main(int argc, char *argv[]) {
    sqlite3 *db = NULL;
    sqlite3_stmt *stmt = NULL;
    int flags = SQLITE_OPEN_READWRITE;
    int rc = 0;
    int idx = -1;
    /* Stringa SQL con i parametri nominativi - named parameters.
    A ogni stringa alfanumerica, usata nelle tre versioni supportate, viene
    associato dalla funzione sqlite3_prepare_v2() un indice numerico. */
    char *sql_str = "INSERT INTO addressbook (fullname, alias, email)"
                    "VALUES(:name, @aka, $mail)";

    if (argc != 5) {
        fprintf(stderr, "Usage: %s <DB>,<name>,<alias>,<email>\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    /* Le stringhe ricevute in input diventano costanti */
    const char *const str_fullname = (argc && argv[2]) ? argv[2] : "";
    const char *const str_alias = (argc && argv[3]) ? argv[3] : "";
    const char *const str_email = (argc && argv[4]) ? argv[4] : "";

    // Library initialization
    if (sqlite3_initialize() != SQLITE_OK) {
        fprintf(stderr, "Err. Unable to initialize the library.\n");
        exit(EXIT_FAILURE);
    }

    // Open database connection
    rc = sqlite3_open_v2(argv[1], &db, flags, NULL);
    if (rc != SQLITE_OK) {
        fprintf(stderr, "Err. can't create database: %s\n", sqlite3_errmsg(db));
        sqlite3_close(db);
        exit(EXIT_FAILURE);
    }

    // Prepare the statement
    rc = sqlite3_prepare_v2(db, sql_str,-1, &stmt, NULL);
    if (rc != SQLITE_OK) {
        fprintf(stderr, "Err. Can't prepare the statement.\n");
        sqlite3_close(db);
        exit(EXIT_FAILURE);
    }

    /* Bind del primo parametro
    Si utilizza la funzione sqlite3_bind_text() per associare il parametro al
    valore che in questo caso e' 'text', poiche' trattasi di stringa.
    L'indice del parametro viene salvato nella variabile intera 'idx', ottenuto
    dal valore di ritorno della funzione sqlite3_bind_parameter_index(): */
    idx = sqlite3_bind_parameter_index(stmt, ":name");
    rc = sqlite3_bind_text(stmt, idx, str_fullname, -1, SQLITE_STATIC);
    if (rc != SQLITE_OK) {
        fprintf(stderr, "Err. Binding the value (%i).\n", rc);
        return 1;
    }

    // Bind del secondo parametro
    idx = sqlite3_bind_parameter_index(stmt, "@aka");
    rc = sqlite3_bind_text(stmt, idx, str_alias, -1, SQLITE_STATIC);
    if (rc != SQLITE_OK) {
        fprintf(stderr, "Err. Binding the value (%i).\n", rc);
        return 1;
    }

    // Bind del terzo parametro
    idx = sqlite3_bind_parameter_index(stmt, "$mail");
    rc = sqlite3_bind_text(stmt, idx, str_email, -1, SQLITE_STATIC);
    if (rc != SQLITE_OK) {
        fprintf(stderr, "Err. Binding the value (%i).\n", rc);
        return 1;
    }

    /* Stampa del totale dei parametri, del nome degli stessi e del 
    rispettivo indice, mediante le funzioni specifiche */
    printf("Total bound parameters: %d\n", sqlite3_bind_parameter_count(stmt));
    
    printf("\'%5s\' index \'%d\'\n", sqlite3_bind_parameter_name(stmt, 1), \
            sqlite3_bind_parameter_index(stmt, ":name"));
    printf("\'%5s\' index \'%d\'\n", sqlite3_bind_parameter_name(stmt, 2), \
            sqlite3_bind_parameter_index(stmt, "@aka"));
    printf("\'%5s\' index \'%d\'\n", sqlite3_bind_parameter_name(stmt, 3), \
            sqlite3_bind_parameter_index(stmt, "$mail"));

    // Execute the statement
    rc = sqlite3_step(stmt);
    if (rc != SQLITE_DONE) {
        fprintf(stderr, "Err. Stepping through the statement.\n");
    } else
        puts("... Statement successfully executed.");

    // Release prepared statement resources
    sqlite3_finalize(stmt);
    // Close database connection
    sqlite3_close_v2(db);
    // Shutdown library initialization
    sqlite3_shutdown();

    return(EXIT_SUCCESS);
}
예제 #17
0
파일: core.c 프로젝트: esmil/lem-sqlite3
static int
bindtable(lua_State *T, sqlite3_stmt *stmt)
{
	int parameters = sqlite3_bind_parameter_count(stmt);
	const char *name;
	const char *err;
	int i;

	for (i = 1; i <= parameters; i++) {
		int ret;

		name = sqlite3_bind_parameter_name(stmt, i);
		lua_settop(T, 2);
		if (name == NULL || name[0] == '?')
			lua_rawgeti(T, 2, i);
		else if (name[0] == '@')
			lua_getfield(T, 2, name + 1);
		else
			lua_getfield(T, 2, name);

		switch (lua_type(T, 3)) {
		case LUA_TNIL:
			/* Should nil mean NULL..
			ret = sqlite3_bind_null(stmt, i);
			break;
			..or don't bind.. */
			continue;

		case LUA_TNUMBER:
			ret = sqlite3_bind_double(stmt, i, lua_tonumber(T, 3));
			break;

		case LUA_TSTRING:
			{
				size_t len;
				const char *str = lua_tolstring(T, 3, &len);

				ret = sqlite3_bind_text(stmt, i,
						str, len, SQLITE_STATIC);
			}
			break;

		default:
			err = "expected nil, number or string";
			goto error;
		}

		if (ret != SQLITE_OK) {
			err = sqlite3_errmsg(sqlite3_db_handle(stmt));
			goto error;
		}
	}
	return 0;

error:
	(void)sqlite3_clear_bindings(stmt);
	luaL_where(T, 1);
	if (name == NULL || name[0] == '?')
		lua_pushfstring(T, "error binding %d: %s", i, err);
	else
		lua_pushfstring(T, "error binding '%s': %s", name, err);
	lua_concat(T, 2);
	return -1;
}
예제 #18
0
파일: interop.c 프로젝트: tobz/dawnoflight
__declspec(dllexport) const char * WINAPI sqlite3_bind_parameter_name_interop(sqlite3_stmt *stmt, int iCol, int *plen)
{
  const char *pval = sqlite3_bind_parameter_name(stmt, iCol);
  *plen = (pval != 0) ? strlen(pval) : 0;
  return pval;
}
예제 #19
0
DLL_FUNCTION(const char*) BU_SQLite_Bind_Parameter_Name(sqlite3_stmt* pStmt, int32_t index) {
#pragma comment(linker, "/EXPORT:BU_SQLite_Bind_Parameter_Name=_BU_SQLite_Bind_Parameter_Name@8")
	return sqlite3_bind_parameter_name(pStmt, index);
}