Example #1
1
void Sqlite::insertData(Data* dt) {
	int out;

	sqlite3_bind_double (insert, 1, dt->getTime());
	sqlite3_bind_double (insert, 2, dt->getLatitude());
	sqlite3_bind_double (insert, 3, dt->getLongitude());
	sqlite3_bind_double (insert, 4, dt->getAltitude());
	sqlite3_bind_double (insert, 5, dt->getHeading());

	while ((out = sqlite3_step(insert)) != SQLITE_DONE) {
		if (out == SQLITE_ERROR) {
			std::cerr << "(" << __FILE__ << ":" << __LINE__ << ") "<< sqlite3_errmsg(dbHandle) << std::endl;
			throw std::exception();
		}
	}
	sqlite3_reset(insert);
}
Example #2
0
int SQLiteStatement::bindDouble(int index, double number)
{
    ASSERT(m_isPrepared);
    ASSERT(index > 0);
    ASSERT(static_cast<unsigned>(index) <= bindParameterCount());

    return sqlite3_bind_double(m_statement, index, number);
}
Example #3
0
void RepoQuery::bindDouble(const char* paramName, double val) {
  sqlite3_stmt* stmt = m_stmt.get();
  int rc UNUSED =
    sqlite3_bind_double(stmt,
                        sqlite3_bind_parameter_index(stmt, paramName),
                        val);
  assert(rc == SQLITE_OK);
}
bool TeSQLite::updatePolygon(const string& table, TePolygon &p)
{
	errorMessage_ = "";

	std::string command = "UPDATE " + table + " SET ";
	command += "object_id=?";
	command += ", lower_x=?, lower_y=?, upper_x=?, upper_y=?, "; 
	command += ", spatial_data=? WHERE geom_id = " + Te2String(p.geomId());


	std::string objectId = p.objectId();

	char* wkb = 0;
	unsigned int wkbSize = 0;

	TeWKBGeometryDecoder::encodePolygon(p, wkb, wkbSize);

	sqlite3_stmt* recordSet = 0;
	int retValue = sqlite3_prepare_v2(_conn, command.c_str(), -1, &recordSet, 0);

	if(retValue != SQLITE_OK)
	{
		errorMessage_ = errorMessage();
		return false;
	}

	sqlite3_bind_text(recordSet, 1, objectId.c_str(), objectId.size(), SQLITE_TRANSIENT);
	sqlite3_bind_double(recordSet, 2, p.box().x1());
	sqlite3_bind_double(recordSet, 3, p.box().y1());
	sqlite3_bind_double(recordSet, 4, p.box().x2());
	sqlite3_bind_double(recordSet, 5, p.box().y2());
	sqlite3_bind_blob(recordSet, 6, wkb, wkbSize, SQLITE_TRANSIENT);

	delete wkb;

	retValue = sqlite3_step(recordSet);
	if(retValue != SQLITE_DONE)
	{
		return false;
	}

	sqlite3_finalize(recordSet);

	return true;
}
Example #5
0
void SqlQuery::bindValue(int pos, const QVariant& value)
{
    int res = -1;
    Q_ASSERT(_stmt);
    if( _stmt ) {
        switch (value.type()) {
        case QVariant::Int:
        case QVariant::Bool:
            res = sqlite3_bind_int(_stmt, pos, value.toInt());
            break;
        case QVariant::Double:
            res = sqlite3_bind_double(_stmt, pos, value.toDouble());
            break;
        case QVariant::UInt:
        case QVariant::LongLong:
            res = sqlite3_bind_int64(_stmt, pos, value.toLongLong());
            break;
        case QVariant::DateTime: {
            const QDateTime dateTime = value.toDateTime();
            const QString str = dateTime.toString(QLatin1String("yyyy-MM-ddThh:mm:ss.zzz"));
            res = sqlite3_bind_text16(_stmt, pos, str.utf16(),
                                      str.size() * sizeof(ushort), SQLITE_TRANSIENT);
            break;
        }
        case QVariant::Time: {
            const QTime time = value.toTime();
            const QString str = time.toString(QLatin1String("hh:mm:ss.zzz"));
            res = sqlite3_bind_text16(_stmt, pos, str.utf16(),
                                      str.size() * sizeof(ushort), SQLITE_TRANSIENT);
            break;
        }
        case QVariant::String: {
            if( !value.toString().isNull() ) {
                // lifetime of string == lifetime of its qvariant
                const QString *str = static_cast<const QString*>(value.constData());
                res = sqlite3_bind_text16(_stmt, pos, str->utf16(),
                                          (str->size()) * sizeof(QChar), SQLITE_TRANSIENT);
            } else {
                // unbound value create a null entry.
                res = SQLITE_OK;
            }
            break;
        }
        default: {
            QString str = value.toString();
            // SQLITE_TRANSIENT makes sure that sqlite buffers the data
            res = sqlite3_bind_text16(_stmt, pos, str.utf16(),
                                      (str.size()) * sizeof(QChar), SQLITE_TRANSIENT);
            break;
        }
        }
    }
    if (res != SQLITE_OK) {
        qDebug() << Q_FUNC_INFO << "ERROR" << value.toString() << res;
    }
    Q_ASSERT( res == SQLITE_OK );
}
Example #6
0
static int sqlite3_bind_cbench_value(sqlite3_stmt *stmt, int ind, struct value *val)
{
	switch (val->type) {
	case VALUE_STRING:
		return sqlite3_bind_text(stmt, ind, val->v_str, -1, SQLITE_STATIC);
	case VALUE_INT32:
		return sqlite3_bind_int(stmt, ind, val->v_int32);
	case VALUE_INT64:
		return sqlite3_bind_int64(stmt, ind, val->v_int64);
	case VALUE_FLOAT:
		return sqlite3_bind_double(stmt, ind, val->v_flt);
	case VALUE_DOUBLE:
		return sqlite3_bind_double(stmt, ind, val->v_dbl);
	default:
		printk(KERN_ERR "bind value: unknown value\n");
		return -1;
	}
}
void SqlConnection::DataCommand::BindFloat(
    SqlConnection::ArgumentIndex position,
    float value)
{
    CheckBindResult(sqlite3_bind_double(m_stmt, position,
                                        static_cast<double>(value)));
    LogPedantic("SQL data command bind float: ["
                << position << "] -> " << value);
}
Example #8
0
static JSBool
js_db_query(JSContext *cx, JSObject *obj, uintN argc,
            jsval *argv, jsval *rval)
{
    const char *query;
    js_db_t *jd = JS_GetPrivate(cx, obj);
    int rc;

    if(js_db_check(cx, jd))
        return JS_FALSE;

    if(!JS_ConvertArguments(cx, argc, argv, "s", &query))
        return JS_FALSE;

    if(jd->jd_stmt) {
        sqlite3_finalize(jd->jd_stmt);
        jd->jd_stmt = NULL;
    }

    rc = db_prepare(jd->jd_db, &jd->jd_stmt, query);

    if(rc != SQLITE_OK) {
        if(jd->jd_transaction && rc == SQLITE_LOCKED) {
            js_txn_deadlock(cx, jd);
            return JS_FALSE;
        }
        *rval = JSVAL_FALSE;
        return JS_TRUE;
    }

    sqlite3_stmt *stmt = jd->jd_stmt;

    for(int i = 1; i < argc; i++) {
        jsval v = argv[i];
        if(JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) {
            sqlite3_bind_null(stmt, i);
        } else if(JSVAL_IS_INT(v)) {
            sqlite3_bind_int(stmt, i, JSVAL_TO_INT(v));
        } else if(JSVAL_IS_BOOLEAN(v)) {
            sqlite3_bind_int(stmt, i, JSVAL_TO_BOOLEAN(v));
        } else if(JSVAL_IS_DOUBLE(v)) {
            double d;
            if(JS_ValueToNumber(cx, v, &d))
                sqlite3_bind_double(stmt, i, d);
        } else if(JSVAL_IS_STRING(v)) {
            JSString *s = JS_ValueToString(cx, v);
            sqlite3_bind_text(stmt, i, JS_GetStringBytes(s), -1, SQLITE_STATIC);
        } else {
            JS_ReportError(cx, "Unable to bind argument %d, invalid type", i);
            sqlite3_finalize(stmt);
            return JS_FALSE;
        }
    }

    *rval = JSVAL_TRUE;
    return js_stmt_step(cx, jd, rval);
}
Example #9
0
 void bind(int where, double d)
 {
     int rc = sqlite3_bind_double(this->_s, where, d);
     if(rc != SQLITE_OK)
     {
         exception e("Could not bind double.");
         throw e;
     }
 }
Example #10
0
int CSQLiteStmt::bind(int nParam, const double dValue)
{
	if( NULL == m_pStmt )
	{
		return -ERROR_FUNCTION_FAILED;
	}

	return sqlite3_bind_double(m_pStmt, nParam, dValue);
}
Example #11
0
 bool operator() (double val)
 {
     if (sqlite3_bind_double(stmt_, index_ , val ) != SQLITE_OK)
     {
         std::cerr << "cannot bind " << val << "\n";
         return false;
     }
     return true;
 }
Example #12
0
int osux_database_bind_double(osux_database *db, char const *name, double d)
{
    int index = sqlite3_bind_parameter_index(db->prepared_query, name);
    if (sqlite3_bind_double(db->prepared_query, index, d) != SQLITE_OK) {
        osux_debug("%s\n", sqlite3_errmsg(get_handle(db)));
        return -OSUX_ERR_DATABASE;
    }
    return 0;
}
Example #13
0
int DB_Record_sensor_values_short(float sensor_value, float measured_timestamp)
{
#if DEVICE_DEBUG
    printf("DB_Record_sensor_values_short.\n");
#endif
    if (pthread_mutex_trylock(&db_token) == 0)
    {
        if (sqlite3_prepare(db, sensor_values_short, strlen(sensor_values_short), &stmt, NULL) != SQLITE_OK)
        {
#if DEVICE_DEBUG
            printf("DB_Record_sensor_values_short: error occur while sqlite3_prepare.\n");
#endif
            return - 1;
        }
        if (sqlite3_bind_double(stmt, 1, sensor_value) != SQLITE_OK)
        {
#if DEVICE_DEBUG
            printf("DB_Record_sensor_values_short: error occur while sqlite3_bind_double.\n");
#endif
            return -1;
        }
        if (sqlite3_bind_double(stmt, 2, measured_timestamp) != SQLITE_OK)
        {
#if DEVICE_DEBUG
            printf("DB_Record_sensor_values_short: error occur while sqlite3_bind_double.\n");
#endif
            return -1;
        }

        sqlite3_step(stmt);  // Run SQL INSERT

        sqlite3_reset(stmt); // Clear statement handle for next use

        pthread_mutex_unlock(&db_token);
    }
    else
    {
#if DEVICE_DEBUG
        printf("Cannot access db token.\n");
#endif
        return - 1;
    }
    return 0;
}
Example #14
0
static void _wi_sqlite3_bind_statement(wi_sqlite3_statement_t *statement, va_list ap) {
	wi_string_t					*string;
	wi_runtime_instance_t		*instance;
	wi_runtime_id_t				id;
	wi_uinteger_t				index;
	int							result;
	
	index = 1;
	
	while((instance = va_arg(ap, wi_runtime_instance_t *))) {
		id			= wi_runtime_id(instance);
		result		= SQLITE_OK;
		
		if(id == wi_string_runtime_id()) {
			result = sqlite3_bind_text(statement->statement, index, wi_string_cstring(instance), wi_string_length(instance), SQLITE_STATIC);
		}
		else if(id == wi_number_runtime_id()) {
			switch(wi_number_storage_type(instance)) {
				case WI_NUMBER_STORAGE_INT8:
				case WI_NUMBER_STORAGE_INT16:
				case WI_NUMBER_STORAGE_INT32:
				case WI_NUMBER_STORAGE_INT64:
					result = sqlite3_bind_int64(statement->statement, index, wi_number_int64(instance));
					break;
					
				case WI_NUMBER_STORAGE_FLOAT:
				case WI_NUMBER_STORAGE_DOUBLE:
					result = sqlite3_bind_double(statement->statement, index, wi_number_double(instance));
					break;
			}
		}
		else if(id == wi_uuid_runtime_id()) {
			string = wi_uuid_string(instance);
			
			result = sqlite3_bind_text(statement->statement, index, wi_string_cstring(string), wi_string_length(string), SQLITE_STATIC);
		}
		else if(id == wi_date_runtime_id()) {
			string = wi_date_sqlite3_string(instance);
			
			result = sqlite3_bind_text(statement->statement, index, wi_string_cstring(string), wi_string_length(string), SQLITE_STATIC);
		}
		else if(id == wi_null_runtime_id()) {
			result = sqlite3_bind_null(statement->statement, index);
		}
		else if(id == wi_data_runtime_id()) {
			result = sqlite3_bind_blob(statement->statement, index, wi_data_bytes(instance), wi_data_length(instance), SQLITE_STATIC);
		}
		else {
			WI_ASSERT(0, "%@ is not a supported data type", instance);
		}
		
		WI_ASSERT(result == SQLITE_OK, "error %d while binding parameter %u", result, index);
		
		index++;
	}
}
Example #15
0
static int db_sqlite_bind_values(sqlite3_stmt* stmt, const db_val_t* v, const int n)
{
	int i, ret;

	if (n>0 && v) {
		for (i=0; i<n; i++) {
			if (VAL_NULL(v+i)) {
				ret=sqlite3_bind_null(stmt, i+1);
				goto check_ret;
			}


			switch(VAL_TYPE(v+i)) {
				/* every param has '+1' index because in sqlite the leftmost
				 * parameter has index '1' */
				case DB_INT:
					ret=sqlite3_bind_int(stmt, i+1, VAL_INT(v+i));
					break;
				case DB_BIGINT:
					ret=sqlite3_bind_int64(stmt, i+1, VAL_BIGINT(v+i));
					break;
				case DB_DOUBLE:
					ret=sqlite3_bind_double(stmt, i+1, VAL_DOUBLE(v+i));
					break;
				case DB_STRING:
					ret=sqlite3_bind_text(stmt, i+1, VAL_STRING(v+i),
											strlen(VAL_STRING(v+i)), SQLITE_STATIC);
					break;
				case DB_STR:
					ret=sqlite3_bind_text(stmt, i+1, VAL_STR(v+i).s,
											VAL_STR(v+i).len, SQLITE_STATIC);
					break;
				case DB_DATETIME:
					ret=sqlite3_bind_int64(stmt, i+1, (long int)VAL_TIME(v+i));
					break;
				case DB_BLOB:
					ret=sqlite3_bind_blob(stmt, i+1, (void*)VAL_BLOB(v+i).s,
											VAL_BLOB(v+i).len, SQLITE_STATIC);
					break;
				case DB_BITMAP:
					ret=sqlite3_bind_int(stmt, i+1, (int)VAL_BITMAP(v+i));
					break;
				default:
					LM_BUG("invalid db type\n");
					return 1;
			}

check_ret:
			if (ret != SQLITE_OK) {
				return ret;
			}
		}
	}

	return SQLITE_OK;
}
 void bind(statement s,int idx,double &val) {
     /** @brief bind argument with a double */
     int rc=sqlite3_bind_double(s,idx,val);
     if (rc) {
         DBError::busy_aware_throw(rc,sqlite3_errmsg(db));
     }
     LOCK_COUT
     cout << "[DB] " << s << ": " << "?" << idx << " = " << val << endl;
     UNLOCK_COUT
 }
Example #17
0
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"));
	}
}
void PlaceDatabase::findInRegion(cv::Rect_<double> bounding_box, std::vector<int64_t>& ids) const
{
  // Bind bounding box in the map to the query
  checkErr(sqlite3_bind_double(select_spatial_stmt_, 1, bounding_box.x), "Bind error");
  checkErr(sqlite3_bind_double(select_spatial_stmt_, 2, bounding_box.x + bounding_box.width), "Bind error");
  checkErr(sqlite3_bind_double(select_spatial_stmt_, 3, bounding_box.y), "Bind error");
  checkErr(sqlite3_bind_double(select_spatial_stmt_, 4, bounding_box.y + bounding_box.height), "Bind error");

  ids.clear();
  int err;
  while ((err = sqlite3_step(select_spatial_stmt_)) == SQLITE_ROW)
    ids.push_back( sqlite3_column_int(select_spatial_stmt_, 0) );
  
  checkErr(err, "Error executing spatial query", SQLITE_DONE);

  // Reset prepared statement to reuse on next call
  checkErr(sqlite3_reset(select_spatial_stmt_), "Couldn't reset SELECT spatial statement");
  checkErr(sqlite3_clear_bindings(select_spatial_stmt_), "Couldn't clear bindings on SELECT spatial statment");
}
gboolean
ephy_sqlite_statement_bind_double (EphySQLiteStatement *self, int column, double value, GError **error)
{
  if (sqlite3_bind_double (self->priv->prepared_statement, column + 1, value) != SQLITE_OK) {
    ephy_sqlite_connection_get_error (self->priv->connection, error);
    return FALSE;
  }

  return TRUE;
}
static void nativeBindDouble(JNIEnv* env, jclass clazz, jlong connectionPtr,
        jlong statementPtr, jint index, jdouble value) {
    SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
    sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr);

    int err = sqlite3_bind_double(statement, index, value);
    if (err != SQLITE_OK) {
        throw_sqlite3_exception(env, connection->db, NULL);
    }
}
Example #21
0
void CppSQLite3Statement::bind(int nParam, const double dValue)
{
	checkVM();
	int nRes = sqlite3_bind_double(mpVM, nParam, dValue);

	if (nRes != SQLITE_OK)
	{
		throw CppSQLite3Exception(nRes,"Error binding double param",DONT_DELETE_MSG);
	}
}
Example #22
0
int StoreAITable(sqlite3 *db, unsigned long int sid, FILE *fp, int swp)
{
    int retval = 0;
    int rc;
    sqlite3_stmt *stmt;
    
    char *sql;

    sql = "INSERT INTO aitransitions" \
          " (sid, ini_id, fin_id, rate)" \
          " VALUES (?, ?, ?, ?)";
    
    sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);

    sqlite3_bind_int(stmt,  1, sid);
    
    sqlite3_exec(db, "BEGIN", 0, 0, 0);

    while (retval == 0) {
        AI_HEADER h;
        int n, i;

        n = ReadAIHeader(fp, &h, swp);
        if (n == 0) {
            break;
        }

        for (i = 0; i < h.ntransitions; i++) {
            AI_RECORD r;
            
            n = ReadAIRecord(fp, &r, swp);
            if (n == 0) {
                break;
            }
            
            sqlite3_bind_int   (stmt,  2, r.b);
            sqlite3_bind_int   (stmt,  3, r.f);
            sqlite3_bind_double(stmt,  4, r.rate);

            rc = sqlite3_step(stmt);
            if (rc != SQLITE_DONE) {
                fprintf(stderr, "SQL error: %s\n", sqlite3_errmsg(db));
                retval = -1;
                break;
            }
            sqlite3_reset(stmt);
        }
    }

    sqlite3_exec(db, "COMMIT", 0, 0, 0);

    sqlite3_finalize(stmt);

    return retval;
}
Example #23
0
int FTNCALL sqlite3_bind_double_c_(
       sqlite3_stmt **stmt,
       int           *colidx,
       double        *value
      )
{
   int   rc   ;

   rc = sqlite3_bind_double(*stmt, *colidx, *value ) ;
   return rc ;
}
Example #24
0
void Lite3Query::bindDouble(int no, double *data, int *null)
{
  if (stmt == 0) prepare();
  int rc;
  if (null != 0 && *null != 0)
    rc = sqlite3_bind_null(stmt, no);
  else
    rc = sqlite3_bind_double(stmt, no, *data);
  if (rc != SQLITE_OK)
    throw Lite3Exception(rc, "Bind of double failed", LITE3_MARK);
}
DB_Error SqliteCommand::Bind(const char* name, double data)
{
    DB_Error ret = DB_INVAL;

    int index = FindParameterIndex(name);
    if (index)
    {
        ret = sqlite3_bind_double(m_stmt, index, data);
    }
    return ret;
}
Example #26
0
void CSQLite3Statement::bindFloat(const int iField, const double dValue)
{
    checkVM();
    CheckParam(iField);

    int iRtn = sqlite3_bind_double(m_pVM, iField + 1, dValue);
    if (iRtn != SQLITE_OK)
    {
        Q_EXCEPTION(sqlite3_errcode(m_pDB), "%s", sqlite3_errmsg(m_pDB));
    }
}
Example #27
0
static double
vknn_rect_distance (VKnnContextPtr ctx, double minx, double miny, double maxx,
		    double maxy)
{
/* computing the distance between the geometry and an R*Tree MBR */
    double dist = DBL_MAX;
    int ret;
    sqlite3_stmt *stmt;
    if (ctx == NULL)
	return DBL_MAX;
    if (ctx->blob == NULL)
	return DBL_MAX;
    if (ctx->stmt_rect == NULL)
	return DBL_MAX;
    stmt = ctx->stmt_rect;
    sqlite3_reset (stmt);
    sqlite3_clear_bindings (stmt);
    sqlite3_bind_blob (stmt, 1, ctx->blob, ctx->blob_size, SQLITE_STATIC);
    sqlite3_bind_double (stmt, 2, minx);
    sqlite3_bind_double (stmt, 3, miny);
    sqlite3_bind_double (stmt, 4, maxx);
    sqlite3_bind_double (stmt, 5, maxy);
    while (1)
      {
	  /* scrolling the result set rows */
	  ret = sqlite3_step (stmt);
	  if (ret == SQLITE_DONE)
	      break;		/* end of result set */
	  if (ret == SQLITE_ROW)
	    {
		if (sqlite3_column_type (stmt, 0) == SQLITE_FLOAT)
		    dist = sqlite3_column_double (stmt, 0);
	    }
	  else
	    {
		dist = DBL_MAX;
		break;
	    }
      }
    return dist;
}
Example #28
0
bool DB::Bindings::bindDouble(int index, double value)
{
	if (!isValid()) {
		DB::logError("Bindings::bindDouble: statement is not valid");
		return false;
	}
	if (sqlite3_bind_double(_handle->_stmt, index, value) != SQLITE_OK) {
		reportError(_handle->_stmt);
		return false;
	}
	return true;
}
Example #29
0
bool SqQuery::BindParamFloat(unsigned int param, float f)
{
	/* SQLite is 1 indexed */
	param++;

	if (param > m_ParamCount)
	{
		return false;
	}

	return (sqlite3_bind_double(m_pStmt, param, (double)f) == SQLITE_OK);
}
Example #30
0
	void SQLiteQuery::BindValue(int index, const SQLiteValue& value)
	{
		if (!stmt) throw SQLiteError(SQL_ERRCODE_NO_INIT);
		if (!index) throw SQLiteError(SQL_ERRCODE_NO_PARAM);

		int result = 0;
		switch (value.type)
		{
		case TYPE_STRING:
			{
				ObjString& str = (ObjString&)*value.object;
				result = sqlite3_bind_text(stmt, index, str.GetValue(),
					-1, SQLITE_TRANSIENT);
			} break;
			
		case TYPE_WSTRING:
			{
				ObjWString& str = (ObjWString&)*value.object;
				result = sqlite3_bind_text16(stmt, index, str.GetValue(),
					-1, SQLITE_TRANSIENT);
			} break;
		case TYPE_INT:
			{
				ObjNumber& num = (ObjNumber&)value.object;
				result = sqlite3_bind_int(stmt, index, (int)num.GetValue());
			}break;
		case TYPE_DOUBLE:
			{
				ObjNumber& num = (ObjNumber&)value.object;
				result = sqlite3_bind_double(stmt, index, num.GetValue());

			}break;
		case TYPE_BLOB:
			{
				ObjBlob& blob = (ObjBlob&)value.object;
				size_t length;
				BYTE* data = blob.GetData(length);
				result = sqlite3_bind_blob(stmt, index, data, length,
					SQLITE_TRANSIENT);

			}break;
		}

		// Handle any errors
		switch (result)
		{
		case SQLITE_OK:
			break;
		default:
			throw SQLiteError(parent.LastError());
			break;
		}	
	}