Example #1
0
VALUE getColumnKeys(VALUE self)

{

    VALUE flag = getIBRubySetting("ALIAS_KEYS"),

          keys = Qnil;



    if(flag == Qtrue)

    {

        keys = getColumnAliases(self);

    }

    else

    {

        keys = getColumnNames(self);

    }



    return(keys);

}
Example #2
0
void SQLiteStatement::executeWithCallback(string query,Binding* bindings,RowCallback callback,Bundle* data){
	this->prepare(query)->bindData(bindings);
	int rc;
	map<string,int> columns;
	while(SQLITE_ROW == (rc = sqlite3_step(m_stmt))) {
		if(columns.empty()){
			columns = getColumnNames();
		}
		callback(this,data);
	}

	if(rc != SQLITE_DONE){
		g_error("Select Query Error: %s",sqlite3_errmsg(this->m_connection));
	}
}
Example #3
0
int applyDelete(sqlite3* db, const Instruction* instr)
{
	int rc;

	auto columnNames = getColumnNames(db, instr->table->tableName);
	std::string sql = std::string() + "DELETE FROM " + instr->table->tableName + " WHERE ";

	uint8_t nCol = instr->table->nCol;

	std::vector<std::string> wheres;
	std::vector<sqlite_value> whereValues;
	for (int i=0; i < nCol; i++)
	{
		if (instr->values[i].type) {
			wheres.push_back(columnNames.at(i) + " = ?");
			whereValues.push_back(instr->values[i]);
		}
	}
	sql += std::accumulate(wheres.cbegin()+1, wheres.cend(), wheres.at(0), [&columnNames](const std::string&a, const std::string& b) {
		return a + " AND " + b;
	});

	sqlite3_stmt* stmt;
	rc = sqlite3_prepare_v2(db, sql.data(), sql.size(), &stmt, nullptr);

	if (rc != SQLITE_OK) {
		std::cerr << "Failed preparing DELETE statement " << sql << std::endl;
		return rc;
	}

	rc = bindValues(stmt, whereValues.data(), whereValues.size());
	if (rc != SQLITE_OK) {
		std::cerr << "Failed binding to DELETE statement " << sql << std::endl;
		return rc;
	}

	rc = sqlite3_step(stmt);
	sqlite3_finalize(stmt);

	if (rc != SQLITE_DONE) {
		return rc;
	}

	return SQLITE_OK;
}
Example #4
0
static int echoDeclareVtab(
  echo_vtab *pVtab, 
  sqlite3 *db 
){
  int rc = SQLITE_OK;

  if( pVtab->zTableName ){
    sqlite3_stmt *pStmt = 0;
    rc = sqlite3_prepare(db, 
        "SELECT sql FROM sqlite_master WHERE type = 'table' AND name = ?",
        -1, &pStmt, 0);
    if( rc==SQLITE_OK ){
      sqlite3_bind_text(pStmt, 1, pVtab->zTableName, -1, 0);
      if( sqlite3_step(pStmt)==SQLITE_ROW ){
        int rc2;
        const char *zCreateTable = (const char *)sqlite3_column_text(pStmt, 0);
        rc = sqlite3_declare_vtab(db, zCreateTable);
        rc2 = sqlite3_finalize(pStmt);
        if( rc==SQLITE_OK ){
          rc = rc2;
        }
      } else {
        rc = sqlite3_finalize(pStmt);
        if( rc==SQLITE_OK ){ 
          rc = SQLITE_ERROR;
        }
      }
      if( rc==SQLITE_OK ){
        rc = getColumnNames(db, pVtab->zTableName, &pVtab->aCol, &pVtab->nCol);
      }
      if( rc==SQLITE_OK ){
        rc = getIndexArray(db, pVtab->zTableName, pVtab->nCol, &pVtab->aIndex);
      }
    }
  }

  return rc;
}
Example #5
0
int SQLiteStatement::getColumnPos(string columnName){
	return (getColumnNames())[columnName];
}
/// Execute the algorithm.
void PDDetermineCharacterizations::exec() {
  // setup property manager to return
  const std::string managerName = getPropertyValue("ReductionProperties");
  if (PropertyManagerDataService::Instance().doesExist(managerName)) {
    m_propertyManager =
        PropertyManagerDataService::Instance().retrieve(managerName);
  } else {
    m_propertyManager = boost::make_shared<Kernel::PropertyManager>();
    PropertyManagerDataService::Instance().addOrReplace(managerName,
                                                        m_propertyManager);
  }

  setDefaultsInPropManager();

  m_characterizations = getProperty(CHAR_PROP_NAME);
  if (bool(m_characterizations) && (m_characterizations->rowCount() > 0)) {
    API::MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
    auto run = inputWS->mutableRun();

    double frequency = getLogValue(run, FREQ_PROP_NAME);

    double wavelength = getLogValue(run, WL_PROP_NAME);

    // determine the container name
    std::string container;
    if (run.hasProperty("SampleContainer")) {
      const auto containerProp = run.getLogData("SampleContainer");

      // the property is normally a TimeSeriesProperty
      const auto containerPropSeries =
          dynamic_cast<TimeSeriesProperty<std::string> *>(containerProp);
      if (containerPropSeries) {
        // assume that only the first value matters
        container = containerPropSeries->valuesAsVector().front();
      } else {
        // try as a normal Property
        container = containerProp->value();
      }

      // remove whitespace from the value
      container = Kernel::Strings::replaceAll(container, " ", "");
    }

    getInformationFromTable(frequency, wavelength, container);
  }

  overrideRunNumProperty("BackRun", "container");
  overrideRunNumProperty("NormRun", "vanadium");
  overrideRunNumProperty("NormBackRun", "vanadium_background");
  overrideRunNumProperty("EmptyEnv", "empty_environment");
  overrideRunNumProperty("EmptyInstr", "empty_instrument");

  std::vector<std::string> expectedNames = getColumnNames();
  for (auto &expectedName : expectedNames) {
    if (m_propertyManager->existsProperty(expectedName)) {
      g_log.debug() << expectedName << ":"
                    << m_propertyManager->getPropertyValue(expectedName)
                    << "\n";
    } else {
      g_log.warning() << expectedName << " DOES NOT EXIST\n";
    }
  }
}
Example #7
0
int applyUpdate(sqlite3* db, const Instruction* instr)
{
	int nCol = instr->table->nCol;

	sqlite_value* valsBefore = instr->values;
	sqlite_value* valsAfter = instr->values + nCol;

	std::vector<std::string> columnNames = getColumnNames(db, instr->table->tableName);

	std::string sql;
	sql = sql + "UPDATE " + instr->table->tableName + " SET";

	// sets
	for (int n=0, i=0; i < nCol; i++) {
		const auto& name = columnNames.at(i);
		const auto val = valsAfter[i];
		if (val.type) {
			if (n > 0) {
				sql += ", ";
			}
			sql = sql + " " + name + " = " + "?";
			n++;
		}
	}

	//wheres
	sql += " WHERE ";
	for (int n=0, i=0; i < nCol; i++) {
		const auto& name = columnNames.at(i);
		const auto val = valsBefore[i];
		if (val.type) {
			if (n > 0) {
				sql += " AND";
			}
			sql = sql + " " + name + " = " + "?";
			n++;
		}
	}

	sqlite3_stmt* stmt; int rc;
	rc = sqlite3_prepare_v2(db, sql.data(), sql.size(), &stmt, nullptr);

	if (rc != SQLITE_OK) {
		std::cerr << "applyUpdate: Failed preparing sql " << sql << std::endl;
		return 1;
	}

	int n = 1;
	for (int i=0; i < nCol; i++) {
		sqlite_value* val = &valsAfter[i];
		if (val->type) {
			if (bindValue(stmt, n, val)) {
				return 1;
			}
			n++;
		}
	}

	for (int i=0; i < nCol; i++) {
		sqlite_value* val = &valsBefore[i];
		if (val->type) {
			if (bindValue(stmt, n, val)) {
				return 1;
			}
			n++;
		}
	}

	rc = sqlite3_step(stmt);

	sqlite3_finalize(stmt);

	if (rc != SQLITE_DONE) {
		return rc;
	}
	return SQLITE_OK;
}