void CRegTestParams::UpdateVersionBitsParametersFromArgs(const ArgsManager& args) { if (!args.IsArgSet("-vbparams")) return; for (const std::string& strDeployment : args.GetArgs("-vbparams")) { std::vector<std::string> vDeploymentParams; boost::split(vDeploymentParams, strDeployment, boost::is_any_of(":")); if (vDeploymentParams.size() != 3) { throw std::runtime_error("Version bits parameters malformed, expecting deployment:start:end"); } int64_t nStartTime, nTimeout; if (!ParseInt64(vDeploymentParams[1], &nStartTime)) { throw std::runtime_error(strprintf("Invalid nStartTime (%s)", vDeploymentParams[1])); } if (!ParseInt64(vDeploymentParams[2], &nTimeout)) { throw std::runtime_error(strprintf("Invalid nTimeout (%s)", vDeploymentParams[2])); } bool found = false; for (int j=0; j < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++j) { if (vDeploymentParams[0] == VersionBitsDeploymentInfo[j].name) { UpdateVersionBitsParameters(Consensus::DeploymentPos(j), nStartTime, nTimeout); found = true; LogPrintf("Setting version bits activation parameters for %s to start=%ld, timeout=%ld\n", vDeploymentParams[0], nStartTime, nTimeout); break; } } if (!found) { throw std::runtime_error(strprintf("Invalid deployment (%s)", vDeploymentParams[0])); } } }
/** * @brief Parse a line in control file. */ bool ReaderParam(Reader *rd, const char *keyword, char *target) { /* * result */ if (CompareKeyword(keyword, "INFILE") || CompareKeyword(keyword, "INPUT")) { ASSERT_ONCE(rd->infile == NULL); rd->infile = pstrdup(target); } else if (CompareKeyword(keyword, "LOGFILE")) { ASSERT_ONCE(rd->logfile == NULL); rd->logfile = pstrdup(target); } else if (CompareKeyword(keyword, "PARSE_BADFILE")) { ASSERT_ONCE(rd->parse_badfile == NULL); rd->parse_badfile = pstrdup(target); } else if (CompareKeyword(keyword, "PARSE_ERRORS") || CompareKeyword(keyword, "MAX_ERR_CNT")) { ASSERT_ONCE(rd->max_parse_errors < -1); rd->max_parse_errors = ParseInt64(target, -1); if (rd->max_parse_errors == -1) rd->max_parse_errors = INT64_MAX; } else if (CompareKeyword(keyword, "LOAD") || CompareKeyword(keyword, "LIMIT")) { ASSERT_ONCE(rd->limit == INT64_MAX); rd->limit = ParseInt64(target, 0); } else if (CompareKeyword(keyword, "CHECK_CONSTRAINTS")) { rd->checker.check_constraints = ParseBoolean(target); } else if (CompareKeyword(keyword, "ENCODING")) { ASSERT_ONCE(rd->checker.encoding < 0); rd->checker.encoding = pg_valid_client_encoding(target); if (rd->checker.encoding < 0) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid encoding for parameter \"ENCODING\": \"%s\"", target))); } else if (rd->parser == NULL || !ParserParam(rd->parser, keyword, target)) return false; return true; }
static __int64 AToI64(const TCHAR* psz, const TCHAR** ppszEnd, bool* pbRange) { __int64 i64; HRESULT hr; if(psz[0]== _T('0') && (psz[1]== _T('x') || psz[1]== _T('X'))) hr = ParseInt64(psz+2, &i64, false, 16, ppszEnd); else hr = ParseInt64(psz, &i64, true, 10, ppszEnd); if(pbRange) *pbRange = hr == E_BL_ERR_RANGE; return i64; }
int64_t UniValue::get_int64() const { if (typ != VNUM) throw std::runtime_error("JSON value is not an integer as expected"); int64_t retval; if (!ParseInt64(getValStr(), &retval)) throw std::runtime_error("JSON integer out of range"); return retval; }
static bool ParseInt64_MTime(const char *p, Int64 &val) { // rare case tar : ZEROs in Docker-Windows TARs // rare case tar : spaces if (GetUi32(p) != 0) for (unsigned i = 0; i < 12; i++) if (p[i] != ' ') return ParseInt64(p, val); val = 0; return true; }
static bool BufferedWriterParam(BufferedWriter *self, const char *keyword, char *value) { if (CompareKeyword(keyword, "TABLE") || CompareKeyword(keyword, "OUTPUT")) { ASSERT_ONCE(self->base.output == NULL); self->base.relid = RangeVarGetRelid(makeRangeVarFromNameList( stringToQualifiedNameList(value)), NoLock, false); self->base.output = get_relation_name(self->base.relid); } else if (CompareKeyword(keyword, "DUPLICATE_BADFILE")) { ASSERT_ONCE(self->base.dup_badfile == NULL); self->base.dup_badfile = pstrdup(value); } else if (CompareKeyword(keyword, "DUPLICATE_ERRORS")) { ASSERT_ONCE(self->base.max_dup_errors < -1); self->base.max_dup_errors = ParseInt64(value, -1); if (self->base.max_dup_errors == -1) self->base.max_dup_errors = INT64_MAX; } else if (CompareKeyword(keyword, "ON_DUPLICATE_KEEP")) { const ON_DUPLICATE values[] = { ON_DUPLICATE_KEEP_NEW, ON_DUPLICATE_KEEP_OLD }; self->base.on_duplicate = values[choice(keyword, value, ON_DUPLICATE_NAMES, lengthof(values))]; } else if (CompareKeyword(keyword, "TRUNCATE")) { self->base.truncate = ParseBoolean(value); } else return false; /* unknown parameter */ return true; }
static bool BinaryParserParam(BinaryParser *self, const char *keyword, char *value) { if (CompareKeyword(keyword, "COL")) { BinaryParam(&self->fields, &self->nfield, value, self->preserve_blanks, false); if (self->fields[self->nfield - 1].character) self->fields[self->nfield - 1].str = palloc(self->fields[self->nfield - 1].len * MAX_CONVERSION_GROWTH + 1); } else if (CompareKeyword(keyword, "PRESERVE_BLANKS")) { self->preserve_blanks = ParseBoolean(value); } else if (CompareKeyword(keyword, "STRIDE")) { ASSERT_ONCE(self->rec_len == 0); self->rec_len = ParseInt32(value, 1); } else if (CompareKeyword(keyword, "SKIP") || CompareKeyword(keyword, "OFFSET")) { ASSERT_ONCE(self->offset < 0); self->offset = ParseInt64(value, 0); } else if (CompareKeyword(keyword, "FILTER")) { ASSERT_ONCE(!self->filter.funcstr); self->filter.funcstr = pstrdup(value); } else return false; /* unknown parameter */ return true; }
static WriterResult ParallelWriterClose(ParallelWriter *self, bool onError) { WriterResult ret = { 0 }; if (!self->base.rel) self->writer->close(self->writer, onError); /* wait for reader */ if (self->conn) { if (self->queue && !onError) { PGresult *res; int sock; fd_set input_mask; /* terminate with zero */ write_queue(self, NULL, 0); do { sock = PQsocket(self->conn); FD_ZERO(&input_mask); FD_SET(sock, &input_mask); while (select(sock + 1, &input_mask, NULL, NULL, NULL) < 0) { if (errno == EINTR) { CHECK_FOR_INTERRUPTS(); continue; } ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("select() failed"), errdetail("%s", finish_and_get_message(self)))); } PQconsumeInput(self->conn); } while (PQisBusy(self->conn)); res = PQgetResult(self->conn); if (PQresultStatus(res) != PGRES_TUPLES_OK) { PQfinish(self->conn); self->conn = NULL; transfer_message(NULL, res); } else { self->base.count = ParseInt64(PQgetvalue(res, 0, 1), 0); ret.num_dup_new = ParseInt64(PQgetvalue(res, 0, 3), 0); ret.num_dup_old = ParseInt64(PQgetvalue(res, 0, 4), 0); PQclear(res); /* commit transaction */ res = PQexec(self->conn, "COMMIT"); if (PQresultStatus(res) != PGRES_COMMAND_OK) { ereport(ERROR, (errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION), errmsg("could not commit transaction"), errdetail("%s", finish_and_get_message(self)))); } } PQclear(res); } else if (PQisBusy(self->conn)) { char errbuf[256]; PGcancel *cancel = PQgetCancel(self->conn); if (cancel) PQcancel(cancel, errbuf, lengthof(errbuf)); } if (self->conn) PQfinish(self->conn); self->conn = NULL; } /* * Close self after wait for reader because reader hasn't opened the self * yet. If we close self too early, the reader cannot open the self. */ if (self->queue) QueueClose(self->queue); self->queue = NULL; if (!onError) { MemoryContextDelete(self->base.context); if (self->base.rel) heap_close(self->base.rel, NoLock); } return ret; }