pike.git / lib / modules / Sql.pmod / pgsql_util.pmod

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:163:    parent->untolderror = 0;    else if (parent->pgsqlsess)    parent->pgsqlsess->untolderror = 0;    parent.delayederror = 0;    if (stringp(err))    err = ({err, backtrace()[..<2]});    throw(err);    }   }    - private int oidformat(int oid) { + private int readoidformat(int oid) {    switch (oid) {    case BOOLOID:    case BYTEAOID:    case CHAROID:    case INT8OID:    case INT2OID:    case INT4OID:    case TEXTOID:    case OIDOID:    case XMLOID: -  +  case DATEOID: +  case TIMEOID: +  case TIMETZOID: +  case TIMESTAMPOID: +  case TIMESTAMPTZOID: +  case INTERVALOID:    case MACADDROID:    case BPCHAROID:    case VARCHAROID:    case CTIDOID:    case UUIDOID:    return 1; //binary    }    return 0; // text   }    -  + private int writeoidformat(int oid, array(string|int) paramValues, +  array(int) ai) { +  mixed value = paramValues[ai[0]++]; +  switch (oid) { +  case BOOLOID: +  case BYTEAOID: +  case CHAROID: +  case INT8OID: +  case INT2OID: +  case INT4OID: +  case TEXTOID: +  case OIDOID: +  case XMLOID: +  case MACADDROID: +  case BPCHAROID: +  case VARCHAROID: +  case CTIDOID: +  case UUIDOID: +  return 1; //binary +  case DATEOID: +  case TIMEOID: +  case TIMETZOID: +  case TIMESTAMPOID: +  case TIMESTAMPTZOID: +  case INTERVALOID: +  if (!stringp(value)) +  return 1; +  } +  return 0; // text + } +  + private array timestamptotype = ({__builtin.Sql.Timestamp, 8, "usecs", 8}); +  + private mapping(int:array) oidtotype = ([ +  DATEOID: ({__builtin.Sql.Date, 4, "days", 4}), +  TIMEOID: ({__builtin.Sql.Time, 8, "usecs", 8}), +  TIMETZOID: ({__builtin.Sql.TimeTZ, 12, "usecs", 8, "timezone", 4}), +  INTERVALOID: +  ({__builtin.Sql.Interval, 16, "usecs", 8, "days", 4, "months", 4}), +  TIMESTAMPOID:timestamptotype, +  TIMESTAMPTZOID:timestamptotype, +  ]); +    private inline mixed callout(function(mixed ...:void) f,    float|int delay, mixed ... args) {    return cb_backend->call_out(f, delay, @args);   }      // Some pgsql utility functions      class bufcon {    inherit Stdio.Buffer;    private Thread.ResourceCountKey dirty;
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:852:    break;    case TEXTOID:    case BPCHAROID:    case VARCHAROID:    value = cr->read(collen);    if (cenc == UTF8CHARSET && catch(value = utf8_to_string(value))    && !serror)    serror = SERROR("%O contains non-%s characters\n",    value, UTF8CHARSET);    break; +  case TIMESTAMPOID: +  case TIMESTAMPTZOID: +  case INTERVALOID: +  case TIMETZOID: +  case TIMEOID: +  case DATEOID: +  if (_forcetext) +  value = cr->read(collen); +  else { +  array totype = oidtotype[typ]; +  value = totype[0](); +  int i = 2; +  do +  value[totype[i]] = cr->read_sint(totype[i+1]); +  while ((i += 2) < sizeof(totype)); +  if (alltext) +  value = (string)value; +  } +  break;    case INT8OID:case INT2OID:    case OIDOID:case INT4OID:    if (_forcetext) {    value = cr->read(collen);    if (!alltext)    value = (int)value;    } else {    switch (typ) {    case INT8OID:value = cr->read_sint(8);    break;
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:912:    + (string)(c->socket->query_fd()) + "_"   #endif    + String.int2hex(pgsqlsess.pportalcount++);    lock = 0;   #ifdef PG_DEBUGMORE    PD("ParamValues to bind: %O\n", paramValues);   #endif    Stdio.Buffer plugbuffer = Stdio.Buffer();    { array dta = ({sizeof(dtoid)});    plugbuffer->add(_portalname, 0, _preparedname, 0) -  ->add_ints(dta + map(dtoid, oidformat) + dta, 2); +  ->add_ints(dta +  + map(dtoid, writeoidformat, paramValues, ({0})) + dta, 2);    }    string cenc = pgsqlsess.runtimeparameter[CLIENT_ENCODING];    foreach (paramValues; int i; mixed value) { -  +  int processtime(object dtype, int tsize, int firstval, int width) { +  if (stringp(value)) { +  plugbuffer->add_hstring(value, 4); +  return 0; +  } else { +  if (!objectp(value)) +  value = dtype(value); +  plugbuffer->add_int32(tsize)->add_int(firstval, width); +  return 1; +  } +  };    if (undefinedp(value) || objectp(value) && value->is_val_null)    plugbuffer->add_int32(-1); // NULL    else if (stringp(value) && !sizeof(value)) {    int k = 0;    switch (dtoid[i]) {    default:    k = -1; // cast empty strings to NULL for non-string types    case BYTEAOID:    case TEXTOID:    case XMLOID:
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:1030:    SUSERERROR(    "\"char\" types must be 1 byte wide, got %O\n", value);    case 0:    plugbuffer->add_int32(-1); // NULL    break;    case 1:    plugbuffer->add_hstring(value[0], 4);    }    }    break; +  case DATEOID: +  case TIMEOID: +  case TIMETZOID: +  case INTERVALOID: +  case TIMESTAMPOID: +  case TIMESTAMPTZOID: +  if (stringp(value)) { +  plugbuffer->add_hstring(value, 4); +  } else { +  array totype = oidtotype[dtoid[i]]; +  if (!objectp(value)) +  value = totype[0](value); +  plugbuffer->add_int32(totype[1]); +  int i = 2; +  do +  plugbuffer->add_int(value[totype[i]], totype[i+1]); +  while ((i += 2) < sizeof(totype)); +  } +  break;    case INT8OID:    plugbuffer->add_int32(8)->add_int((int)value, 8);    break;    case OIDOID:    case INT4OID:    plugbuffer->add_int32(4)->add_int32((int)value);    break;    case INT2OID:    plugbuffer->add_int32(2)->add_int16((int)value);    break;
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:1052:    if (!datarowtypes) {    if (_tprepared && dontcacheprefix->match(_query))    m_delete(pgsqlsess->prepareds, _query), _tprepared = 0;    waitfordescribe();    }    if (_state >= CLOSING)    lock = _unnamedstatementkey = 0;    else {    plugbuffer->add_int16(sizeof(datarowtypes));    if (sizeof(datarowtypes)) -  plugbuffer->add_ints(map(datarowtypes, oidformat), 2); +  plugbuffer->add_ints(map(datarowtypes, readoidformat), 2);    else if (syncparse < 0 && !pgsqlsess->wasparallelisable    && !pgsqlsess->statementsinflight->drained(1)) {    lock = pgsqlsess->shortmux->lock();    PD("Commit waiting for statements to finish\n");    catch(PT(pgsqlsess->statementsinflight->wait_till_drained(lock, 1)));    }    lock = 0;    PD("Bind portal %O statement %O\n", _portalname, _preparedname);    _fetchlimit = pgsqlsess->_fetchlimit;    _bindportal();