Пример #1
0
/*
 * Dump user-and-database-specific configuration
 */
static void
dumpDbRoleConfig(PGconn *conn)
{
	PQExpBuffer buf = createPQExpBuffer();
	PGresult   *res;
	int			i;

	printfPQExpBuffer(buf, "SELECT rolname, datname, unnest(setconfig) "
					  "FROM pg_db_role_setting, pg_authid, pg_database "
		  "WHERE setrole = pg_authid.oid AND setdatabase = pg_database.oid");
	res = executeQuery(conn, buf->data);

	if (PQntuples(res) > 0)
	{
		fprintf(OPF, "--\n-- Per-Database Role Settings \n--\n\n");

		for (i = 0; i < PQntuples(res); i++)
		{
			makeAlterConfigCommand(conn, PQgetvalue(res, i, 2),
								   "ROLE", PQgetvalue(res, i, 0),
								   "DATABASE", PQgetvalue(res, i, 1));
		}

		fprintf(OPF, "\n\n");
	}

	PQclear(res);
	destroyPQExpBuffer(buf);
}
Пример #2
0
static void
reindex_all_databases(const char *host, const char *port,
					  const char *username, enum trivalue prompt_password,
					  const char *progname, bool echo, bool quiet)
{
	PGconn	   *conn;
	PGresult   *result;
	int			i;

	conn = connectDatabase("postgres", host, port, username, prompt_password, progname);
	result = executeQuery(conn, "SELECT datname FROM pg_database WHERE datallowconn ORDER BY 1;", progname, echo);
	PQfinish(conn);

	for (i = 0; i < PQntuples(result); i++)
	{
		char	   *dbname = PQgetvalue(result, i, 0);

		if (!quiet)
		{
			printf(_("%s: reindexing database \"%s\"\n"), progname, dbname);
			fflush(stdout);
		}

		reindex_one_database(dbname, dbname, "DATABASE", host, port, username,
							 prompt_password, progname, echo);
	}

	PQclear(result);
}
Пример #3
0
/*
 * Dump database-specific configuration
 */
static void
dumpDatabaseConfig(PGconn *conn, const char *dbname)
{
    PQExpBuffer buf = createPQExpBuffer();
    int			count = 1;

    for (;;)
    {
        PGresult   *res;

        printfPQExpBuffer(buf, "SELECT datconfig[%d] FROM pg_database WHERE datname = ", count);
        appendStringLiteralConn(buf, dbname, conn);
        appendPQExpBuffer(buf, ";");

        res = executeQuery(conn, buf->data);
        if (!PQgetisnull(res, 0, 0))
        {
            makeAlterConfigCommand(conn, PQgetvalue(res, 0, 0),
                                   "DATABASE", dbname);
            PQclear(res);
            count++;
        }
        else
        {
            PQclear(res);
            break;
        }
    }

    destroyPQExpBuffer(buf);
}
Пример #4
0
/*
 * Drop tablespaces.
 */
static void
dropTablespaces(PGconn *conn)
{
	PGresult   *res;
	int			i;

	/*
	 * Get all tablespaces except built-in ones (which we assume are named
	 * pg_xxx)
	 */
	res = executeQuery(conn, "SELECT spcname "
					   "FROM pg_catalog.pg_tablespace "
					   "WHERE spcname !~ '^pg_' "
					   "ORDER BY 1");

	if (PQntuples(res) > 0)
		fprintf(OPF, "--\n-- Drop tablespaces\n--\n\n");

	for (i = 0; i < PQntuples(res); i++)
	{
		char	   *spcname = PQgetvalue(res, i, 0);

		fprintf(OPF, "DROP TABLESPACE %s;\n", fmtId(spcname));
	}

	PQclear(res);

	fprintf(OPF, "\n\n");
}
Пример #5
0
std::map<SensorType, int> Sql::getSensorsFromNode(int nodeID)
{
	std::string query("SELECT temperatureID, humidityID, pressureID, batteryID, co2ID, anemoID, vaneID, pluvioID  from  nodes WHERE nodeID = " + std::to_string(nodeID));
	auto data = executeQuery(query);
	std::cout << "data.size() " << data.size() << std::endl;
	if (data.size() != 1)
	{
		throw SqlError();
	}

	std::map<SensorType, int> sensors;
	auto it = data.begin();
	std::map<std::string, std::string>::iterator  field;
	CHECKSENSOR(temperatureID, TEMP)
	CHECKSENSOR(humidityID, HUM)
	CHECKSENSOR(pressureID, PRES)
	CHECKSENSOR(batteryID, BAT)
	CHECKSENSOR(co2ID, CO2)
	CHECKSENSOR(anemoID, ANEMO)
	CHECKSENSOR(vaneID, VANE)
	CHECKSENSOR(pluvioID, PLUVIO)
	/*	
	field = it->find("temperatureID");
	if(field != it->end())
	{
		if(field->second != std::string("-1"))
		{	
			sensors.insert(std::pair<SensorType,int>(TEMP, boost::lexical_cast<int>(field->second)));
		}	
	}
	*/	

	return sensors;

}
void CommandDownloadFile::exec(const QUrl &downloadUrl, QIODevice *out)
{
    Q_D(CommandDownloadFile);
    d->downloadUrl = downloadUrl;
    d->out = out;
    executeQuery();
}
Пример #7
0
/*
 * Dump user-specific configuration
 */
static void
dumpUserConfig(PGconn *conn, const char *username)
{
    PQExpBuffer buf = createPQExpBuffer();
    int			count = 1;

    for (;;)
    {
        PGresult   *res;

        if (server_version >= 80100)
            printfPQExpBuffer(buf, "SELECT rolconfig[%d] FROM pg_authid WHERE rolname = ", count);
        else
            printfPQExpBuffer(buf, "SELECT useconfig[%d] FROM pg_shadow WHERE usename = ", count);
        appendStringLiteralConn(buf, username, conn);

        res = executeQuery(conn, buf->data);
        if (PQntuples(res) == 1 &&
                !PQgetisnull(res, 0, 0))
        {
            makeAlterConfigCommand(conn, PQgetvalue(res, 0, 0),
                                   "ROLE", username);
            PQclear(res);
            count++;
        }
        else
        {
            PQclear(res);
            break;
        }
    }

    destroyPQExpBuffer(buf);
}
Пример #8
0
static void
vacuum_all_databases(bool full, bool verbose, bool and_analyze, bool analyze_only,
					 bool freeze, const char *host, const char *port,
					 const char *username, enum trivalue prompt_password,
					 const char *progname, bool echo, bool quiet)
{
	PGconn	   *conn;
	PGresult   *result;
	int			i;

	conn = connectDatabase("postgres", host, port, username, prompt_password, progname);
	result = executeQuery(conn, "SELECT datname FROM pg_database WHERE datallowconn ORDER BY 1;", progname, echo);
	PQfinish(conn);

	for (i = 0; i < PQntuples(result); i++)
	{
		char	   *dbname = PQgetvalue(result, i, 0);

		if (!quiet)
		{
			printf(_("%s: vacuuming database \"%s\"\n"), progname, dbname);
			fflush(stdout);
		}

		vacuum_one_database(dbname, full, verbose, and_analyze, analyze_only,
						 freeze, NULL, host, port, username, prompt_password,
							progname, echo);
	}

	PQclear(result);
}
CommunicatorCommand MySQLFactorerCommunicator::getCommand(MPIAlgorithm::AlgorithmsEnum& algorithm, std::string& number)
{
    try
    {
        sql::ResultSet *res = nullptr;
        bool wait = false;

        do{
            res = executeQuery(
                "SELECT id, number_to_factor, algorithm_id FROM FactorerMain_task WHERE state = 0 ORDER BY job_date;");
            wait = (res->next() == false);
            if( wait )
            {
                delete res;
                res = nullptr;
                sleep(SLEEP_TIME);
            }
        }while( wait );

        currentTaskId = res->getInt(1);
        number = res->getString(2);
        algorithm = MPIAlgorithm::AlgorithmsEnum(res->getInt(3));//TODO THAT'S BADs

        delete res;
        }
        catch (sql::SQLException &e)
         {
            std::string msg("ERR: ");
            msg.append( e.what());
            throw FactorerCommunicatorException(msg);
        }

        return CommunicatorCommand::Algorithm;
}
Пример #10
0
QList<Message> HistorySqlStorage::messagesBackTo(const Chat &chat, const QDateTime &datetime, int limit)
{
	DatabaseMutex.lock();

	QList<Message> result;

	QSqlQuery query(Database);
	// we want last *limit* messages, so we have to invert sorting here
	// it is reverted back manually below
	QString queryString = "SELECT chat, sender, content, send_time, receive_time, attributes FROM kadu_messages WHERE " + chatWhere(chat) +
			" AND datetime(receive_time) >= datetime(:date) ORDER BY receive_time DESC, rowid DESC LIMIT :limit";
	query.prepare(queryString);

	query.bindValue(":chat", chat.uuid().toString());
	query.bindValue(":date", datetime.toString(Qt::ISODate));
	query.bindValue(":limit", limit);

	executeQuery(query);

	result = messagesFromQuery(query);

	DatabaseMutex.unlock();

	// se comment above
	QList<Message> inverted;
#if (QT_VERSION >= 0x040700)
	inverted.reserve(result.size());
#endif
	for (int i = result.size() - 1; i >= 0; --i)
		inverted.append(result.at(i));
	return inverted;
}
Пример #11
0
static void
cluster_all_databases(bool verbose, const char *maintenance_db,
					  const char *host, const char *port,
					  const char *username, enum trivalue prompt_password,
					  const char *progname, bool echo, bool quiet)
{
	PGconn	   *conn;
	PGresult   *result;
	int			i;

	conn = connectMaintenanceDatabase(maintenance_db, host, port, username,
									  prompt_password, progname);
	result = executeQuery(conn, "SELECT datname FROM pg_database WHERE datallowconn ORDER BY 1;", progname, echo);
	PQfinish(conn);

	for (i = 0; i < PQntuples(result); i++)
	{
		char	   *dbname = PQgetvalue(result, i, 0);

		if (!quiet)
		{
			printf(_("%s: clustering database \"%s\"\n"), progname, dbname);
			fflush(stdout);
		}

		cluster_one_database(dbname, verbose, NULL,
							 host, port, username, prompt_password,
							 progname, echo);
	}

	PQclear(result);
}
Пример #12
0
QList<Message> HistorySqlStorage::messages(const Chat &chat, const QDate &date, int limit)
{
	kdebugf();

	DatabaseMutex.lock();

	QSqlQuery query(Database);
	QString queryString = "SELECT chat, sender, content, send_time, receive_time, attributes FROM kadu_messages WHERE " + chatWhere(chat);
	if (!date.isNull())
		queryString += " AND date(receive_time) = date(:date)";
	queryString += " ORDER BY receive_time ASC, rowid ASC";
	if (0 != limit)
		queryString += " LIMIT :limit";

	QList<Message> messages;
	query.prepare(queryString);

	if (!date.isNull())
		query.bindValue(":date", date.toString(Qt::ISODate));
	if (limit != 0)
		query.bindValue(":limit", limit);
	executeQuery(query);
	messages = messagesFromQuery(query);

	DatabaseMutex.unlock();

	return messages;
}
Пример #13
0
QList<Message> HistorySqlStorage::messagesSince(const Chat &chat, const QDate &date)
{
	kdebugf();

	DatabaseMutex.lock();

	QList<Message> messages;
	if (date.isNull())
		return messages;

	QSqlQuery query(Database);
	QString queryString = "SELECT chat, sender, content, send_time, receive_time, attributes FROM kadu_messages WHERE " + chatWhere(chat) +
			" AND date(receive_time) >= date(:date) ORDER BY receive_time ASC, rowid ASC";
	query.prepare(queryString);

	query.bindValue(":chat", chat.uuid().toString());
	query.bindValue(":date", date.toString(Qt::ISODate));

	executeQuery(query);

	messages = messagesFromQuery(query);

	DatabaseMutex.unlock();

	return messages;
}
Пример #14
0
/*! \brief Returns count of all items in the feed.
    \attention In XQuery item count starts from 1.
    \return count of items
    \sa isError()
*/
int RSSParser::count() {
    if(m_InvalidateCachedCount) {
        m_Count = executeQuery(KXqItemCount).toInt();
        m_InvalidateCachedCount = false;
    }
    return m_Count;
}
Пример #15
0
//----------------------------------------------------------------------------
void ctkPluginStorageSQL::cleanupDB()
{
  QSqlDatabase database = getConnection();
  QSqlQuery query(database);

  beginTransaction(&query, Write);

  try
  {
    // remove all plug-ins marked as UNINSTALLED
    QString statement = "DELETE FROM " PLUGINS_TABLE " WHERE StartLevel==-2";
    executeQuery(&query, statement);

    // remove all old plug-in generations
    statement = "DELETE FROM " PLUGINS_TABLE
                " WHERE K NOT IN (SELECT K FROM (SELECT K, MAX(Generation) FROM " PLUGINS_TABLE " GROUP BY ID))";
  }
  catch (...)
  {
    rollbackTransaction(&query);
    throw;
  }

  commitTransaction(&query);
}
Пример #16
0
	LiveNode RDFGraphBasic::implLiveNode
			( LiveNode const &node, LiveNode const &type, bool strict
			, QList<QUrl> const &resource_contexts)
	{
		if(!node.isValid())
			return node;

		// if this graph implements the any of the supplied resource_contexts,
		// it is given that resource exists and has requested types, thus skip checks
		if(!node.isLiteral()
				&& (!resource_contexts.size() || !isAnyContextImplemented(resource_contexts)))
		{
			RDFVariable type_var(type.isValid()
					? type.variable()
					: RDFVariable(rdfs::Resource::iri()));
			if(strict)
			{
				RDFVariable checker = RDFVariable::fromType(type_var);
				checker == node;
				if(!modelVariable(checker)->rowCount())
					return LiveNode();
			} else
				// derived type implies all base types, suffices to add only it
				executeQuery(service_context_data_->update()
						.addInsertion(node, rdf::type::iri(), type_var));
		}

		if(node.isLive() && node->graph() == this)
			// checks have been made and node already is on this graph, return it directly
			return node;

		// otherwise, create a new node
		return newLiveResource(node)->initialSharedFromThis<LiveResource>();
	}
Пример #17
0
void  Sql::removeIpsumPacket(int id)
{
	std::string query("DELETE FROM ipsum_packets WHERE id = '");
	query.append(std::to_string(id));
	query.append("'");
	executeQuery(query);
}
Пример #18
0
QList<Message> HistorySqlStorage::sms(const QString &recipient, const QDate &date, int limit)
{
	kdebugf();

	DatabaseMutex.lock();

	QSqlQuery query(Database);
	QString queryString = "SELECT content, send_time FROM kadu_sms WHERE receipient = :receipient";
	if (!date.isNull())
		queryString += " AND date(send_time) = date(:date)";
	queryString += " ORDER BY send_time ASC";
	if (0 != limit)
		queryString += " LIMIT :limit";

	query.prepare(queryString);

	query.bindValue(":receipient", recipient);
	if (!date.isNull())
		query.bindValue(":date", date.toString(Qt::ISODate));
	if (limit != 0)
		query.bindValue(":limit", limit);
	executeQuery(query);

	QList<Message> result = smsFromQuery(query);

	DatabaseMutex.unlock();

	return result;
}
Пример #19
0
std::string SQLUtility::getGUCValue(const std::string &guc) {
    string sql = "show " + guc;
    const hawq::test::PSQLQueryResult &result = executeQuery(sql);
    EXPECT_EQ(result.rowCount(), 1);
    std::vector<std::string> row = result.getRows()[0];
    return row[0];
}
Пример #20
0
std::string Sql::updateSensorsInNode(int nodeID, SensorType name, int sensorID)	
{
	std::string sensorName;
	switch(name)
	{
		case TEMP:
			sensorName = "temperatureID";
		break;	
		case HUM:
			sensorName = "humidityID";
		break;	
		case PRES:
			sensorName = "pressureID";
		break;	
		case BAT:
			sensorName = "batteryID";
		break;	
		case CO2:
			sensorName = "co2ID";
		break;	
		case ANEMO:
			sensorName = "anemoID";
		break;	
		case VANE:
			sensorName = "vaneID";
		break;	
		case PLUVIO:
			sensorName = "pluvioID";
		break;	

	}
	std::string query("UPDATE nodes SET " + sensorName + "=" + std::to_string(sensorID) + " WHERE nodeID=" + std::to_string(nodeID));
	executeQuery(query);
	return query;	
}
Пример #21
0
/*
 * Dump contents of databases.
 */
static void
dumpDatabases(PGconn *conn)
{
	PGresult   *res;
	int			i;

	if (server_version >= 70100)
		res = executeQuery(conn, "SELECT datname FROM pg_database WHERE datallowconn ORDER BY 1");
	else
		res = executeQuery(conn, "SELECT datname FROM pg_database ORDER BY 1");

	for (i = 0; i < PQntuples(res); i++)
	{
		int			ret;

		char	   *dbname = PQgetvalue(res, i, 0);

		if (verbose)
			fprintf(stderr, _("%s: dumping database \"%s\"...\n"), progname, dbname);

		fprintf(OPF, "\\connect %s\n\n", fmtId(dbname));

		if (filename)
			fclose(OPF);

		ret = runPgDump(dbname);
		if (ret != 0)
		{
			fprintf(stderr, _("%s: pg_dump failed on database \"%s\", exiting\n"), progname, dbname);
			exit(1);
		}

		if (filename)
		{
			OPF = fopen(filename, PG_BINARY_A);
			if (!OPF)
			{
				fprintf(stderr, _("%s: could not re-open the output file \"%s\": %s\n"),
						progname, filename, strerror(errno));
				exit(1);
			}
		}

	}

	PQclear(res);
}
Пример #22
0
//エラーハンドリング月
void SqliteManager::executeQueryByString(const std::string &query)
{
    _result = executeQuery(query);
    if (_result != SQLITE_OK)
    {
        CCLOG("エラー%d:%s", _result, _error_msg);
    }
}
Пример #23
0
int Database::allItemsCount(QString query_) const {
    QSqlQuery query = executeQuery(query_);

    while(query.next()) {
        return query.value(0).toInt();
    }
    return 0;
}
Пример #24
0
int ProjectsTable::selectProjectNotAssigned()
{
	const std::string query =
			"select id_project from main_site_projects "
			"where assigned = 0 "
			"limit 1;";
	return executeQuery(query);
}
Пример #25
0
bool ProjectsTable::setProjectAssigned(int project_id)
{
	std::string query =
			"update main_site_projects "
				"set assigned=1 "
				"where id_project=" + std::to_string(project_id) + ";";
	return executeQuery(query);
}
Пример #26
0
int SVGTextQuery::characterNumberAtPosition(const FloatPoint& position) const
{
    CharacterNumberAtPositionData data(position);
    if (!executeQuery(&data, &SVGTextQuery::characterNumberAtPositionCallback))
        return -1;

    return data.processedCharacters;
}
Пример #27
0
bool Database::beginTransaction()
{
	if (!executeQuery("BEGIN")) {
		return false;
	}

	database_lock.lock();
	return true;
}
Пример #28
0
SVGRect SVGTextQuery::extentOfCharacter(unsigned position) const
{
    if (m_textBoxes.isEmpty())
        return SVGRect();

    ExtentOfCharacterData data(position);
    executeQuery(&data, &SVGTextQuery::extentOfCharacterCallback);
    return data.extent;
}
Пример #29
0
float SVGTextQuery::rotationOfCharacter(unsigned position) const
{
    if (m_textBoxes.isEmpty())
        return 0;

    RotationOfCharacterData data(position);
    executeQuery(&data, &SVGTextQuery::rotationOfCharacterCallback);
    return data.rotation;
}
Пример #30
0
FloatPoint SVGTextQuery::endPositionOfCharacter(unsigned position) const
{
    if (m_textBoxes.isEmpty())
        return FloatPoint();

    EndPositionOfCharacterData data(position);
    executeQuery(&data, &SVGTextQuery::endPositionOfCharacterCallback);
    return data.endPosition;
}