示例#1
0
/*--------------------------------------------------------------------------------*/
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;
}
示例#2
0
bool ADVBConfig::ExtractLogData(const ADateTime& start, const ADateTime& end, const AString& filename) const
{
	AStdFile dst;
	bool success = false;

	if (dst.open(filename, "w")) {
		ADateTime dt;
		uint32_t day1 = start.GetDays();
		uint32_t day2 = end.GetDays();
		uint32_t day;
		bool     valid = false;

		for (day = day1; day <= day2; day++) {
			AStdFile src;

			if (src.open(GetLogFile(day))) {
				AString line;

				while (line.ReadLn(src) >= 0) {
					valid |= dt.FromTimeStamp(line.Words(0, 2));

					if (valid) {
						if ((dt >= start) && (dt <= end)) dst.printf("%s\n", line.str());
						if (dt >= end) break;
					}
				}

				src.close();
			}
		}

		dst.close();
	}

	return success;
}