本文整理汇总了C++中AString::printf方法的典型用法代码示例。如果您正苦于以下问题:C++ AString::printf方法的具体用法?C++ AString::printf怎么用?C++ AString::printf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AString
的用法示例。
在下文中一共展示了AString::printf方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetColumnType
/*--------------------------------------------------------------------------------*/
AString PostgresDatabase::GetColumnType(const AString& column) const
{
AString ctype = column.Word(1);
AString type;
if ((type = ConvertSimpleType(ctype)).Empty())
{
if (ctype == "references") type.printf("integer references %s", column.Word(2).str()); // reference to another table
else if (ctype == "references64") type.printf("bigint references %s", column.Word(2).str()); // reference to another table (with 64-bit id)
else type = ctype;
}
return type;
}
示例2: Open
/*--------------------------------------------------------------------------------*/
bool PostgresDatabase::Open(const AString& host, const AString& username, const AString& password, const AString& database)
{
bool success = false;
if (!conn) {
AString str;
ClearResult();
connstr.Delete();
connstr.printf("postgresql://%s:%[email protected]%s", username.str(), password.str(), host.str());
if (CheckConnection()) {
str = connstr;
if (database.Valid()) str.printf("/%s", database.ToLower().str());
success = (((conn = PQconnectdb(str.str())) != NULL) && (PQstatus(conn) == CONNECTION_OK));
if (success) {
if (database.Valid()) debug("Connected to database '%s' on %s\n", database.str(), host.str());
isopen = true;
}
else {
if (database.Valid()) debug("Failed to connect to database '%s' on %s: %s\n", database.str(), host.str(), GetErrorMessage().str());
else debug("Failed to connect server %s: %s\n", host.str(), GetErrorMessage().str());
Close();
}
}
else debug("No connection to server!\n");
}
return success;
}
示例3: CheckConnection
/*--------------------------------------------------------------------------------*/
bool PostgresDatabase::CheckConnection(const AString& host)
{
AString connstr;
connstr.printf("postgresql://%s", host.str());
bool success = (PQping(connstr) == PQPING_OK);
debug("Checking connection to %s...%s\n", host.str(), success ? "success" : "**failure**");
return success;
}
示例4: PQgetvalue
/*--------------------------------------------------------------------------------*/
bool PostgresDatabase::PostgresQuery::Fetch(AString& results)
{
bool success = false;
if (res && nfields && (row < nrows)) {
uint_t i;
results.Delete();
for (i = 0; i < nfields; i++) {
if (i) results.printf(",");
const char *p = PQgetvalue(res, row, i);
switch (PQftype(res, i)) {
case TIMESTAMPOID: {
ADateTime dt;
dt.FromTimeStamp(p, true);
results += AString((uint64_t)dt);
//debug("%s->%llu->%s (%s)\n", p, (uint64)dt, dt.DateFormat("%Y-%M-%D %h:%m:%s.%S").str(), dt.UTCToLocal().DateFormat("%Y-%M-%D %h:%m:%s.%S").str());
break;
}
case TEXTOID:
case CHAROID:
case VARCHAROID:
results.printf("'%s'", AString(p).Escapify().str());
break;
default:
results.printf("%s", p);
break;
}
}
//debug("Row %u/%u: %s\n", row, nrows, results.str());
row++;
success = true;
}
return success;
}
示例5: SendFileToRecordingSlave
bool SendFileToRecordingSlave(const AString& filename)
{
const ADVBConfig& config = ADVBConfig::Get();
AString cmd;
bool success;
//config.logit("'%s' -> '%s:%s'...", filename.str(), config.GetRecordingSlave().str(), filename.str());
cmd.printf("scp -p -C -P %u %s \"%s\" %s:\"%s\"", config.GetRecordingSlavePort(), config.GetSCPArgs().str(), filename.str(), config.GetRecordingSlave().str(), filename.str());
success = RunAndLogCommand(cmd);
//config.logit("'%s' -> '%s:%s' %s", filename.str(), config.GetRecordingSlave().str(), filename.str(), success ? "success" : "failed");
return success;
}
示例6: CreateTable
/*--------------------------------------------------------------------------------*/
bool PostgresDatabase::CreateTable(const AString& name, const AString& columns)
{
AString sql;
SQLQuery *query = NULL;
uint_t i, n = columns.CountColumns();
sql.printf("create table %s (", name.str());
for (i = 0; i < n; i++) {
AString column = columns.Column(i);
if (i > 0) sql.printf(", ");
sql.printf("%s %s", column.Word(0).str(), GetColumnType(column).str());
}
sql.printf(")");
if ((query = RunQuery(sql)) != NULL) {
bool success = query->GetResult();
delete query;
return success;
}
return false;
}
示例7: ConvertSimpleType
/*--------------------------------------------------------------------------------*/
AString PostgresDatabase::ConvertSimpleType(const AString& ctype) const
{
AString type;
if (ctype == "id") type = "integer not null primary key"; // primary key id
else if (ctype == "id64") type = "bigint not null primary key"; // primary key id (64-bit)
else if (ctype.Left(6) == "string") type.printf("varchar%s", ctype.Mid(6).SearchAndReplace("[", "(").SearchAndReplace("]", ")").str()); // string type / varchar
else if (ctype == "datetime") type = "timestamp";
else if (ctype == "float") type = "real";
else if (ctype == "double") type = "real";
else if (ctype == "short") type = "smallint";
else if (ctype == "int64") type = "bigint";
else if (ctype == "") type = "integer";
return type;
}
示例8: GetPatternDefinitionsJSON
AString ADVBPatterns::GetPatternDefinitionsJSON()
{
AString str;
uint_t i, j, nfields;
const FIELD *fields = ADVBProg::GetFields(nfields);
str.printf("\"patterndefs\":");
str.printf("{\"fields\":[");
for (i = 0; i < nfields; i++) {
const FIELD& field = fields[i];
if (i) str.printf(",");
str.printf("{\"name\":\"%s\"", JSONFormat(field.name).str());
str.printf(",\"desc\":\"%s\"", JSONFormat(field.desc).str());
str.printf(",\"type\":%u", field.type);
str.printf(",\"assignable\":%s", field.assignable ? "true" : "false");
str.printf(",\"operators\":[");
bool flag = false;
for (j = 0; j < NUMBEROF(operators); j++) {
const OPERATOR& oper = operators[j];
if ((field.assignable == oper.assign) &&
(oper.fieldtypes & (1U << field.type))) {
if (flag) str.printf(",");
str.printf("%u", j);
flag = true;
}
}
str.printf("]}");
}
str.printf("]");
str.printf(",\"fieldnames\":{");
for (i = 0; i < nfields; i++) {
const FIELD& field = fields[i];
if (i) str.printf(",");
str.printf("\"%s\":%u", JSONFormat(field.name).str(), i);
}
str.printf("}");
str.printf(",\"operators\":[");
for (j = 0; j < NUMBEROF(operators); j++) {
const OPERATOR& oper = operators[j];
if (j) str.printf(",");
str.printf("{\"text\":\"%s\"", JSONFormat(oper.str).str());
str.printf(",\"desc\":\"%s\"", JSONFormat(oper.desc).str());
str.printf(",\"opcode\":%u", (uint_t)oper.opcode);
str.printf(",\"assign\":%s}", oper.assign ? "true" : "false");
}
str.printf("]");
str.printf(",\"orflags\":[");
for (j = 0; j < 2; j++) {
if (j) str.printf(",");
str.printf("{\"text\":\"%s\"", JSONFormat(j ? "or" : "and").str());
str.printf(",\"desc\":\"%s\"", JSONFormat(j ? "Or the next term" : "And the next term").str());
str.printf(",\"value\":%u}", j);
}
str.printf("]}");
return str;
}