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

version» Context lines:

pike.git/lib/modules/Sql.pmod/rsql.pike:16:      #define ERROR(X ...) predef::error(X)      protected object(Stdio.File) sock;   protected int seqno = 0;      protected private string host, user, pw;   protected private int port;   protected private mapping options;    + protected private string db; +    protected void low_reconnect()   {    object losock = Stdio.File();    if(sock)    destruct(sock);    if (host == "") {   #ifdef ENABLE_SPAWN_RSQLD    Process.spawn_pike(({ "-x", "rsqld", "--stdin" }), ([    "stdin":losock->pipe(),    ]));
pike.git/lib/modules/Sql.pmod/rsql.pike:63:    port = the_port;    user = the_user;    pw = the_pw;    options = the_options;    low_reconnect();   }      protected mixed do_request(int cmd, mixed|void arg, int|void noreconnect)   {    LOCK; +  noreconnect = noreconnect || !options || !options->reconnect;    if(!sock)    if(noreconnect) {    UNLOCK;    ERROR("No connection\n"); -  } else +  } else { +  UNLOCK;    low_reconnect(); -  +  select_db(db); +  LOCK; +  noreconnect = 1; +  }    arg = (arg? encode_value(arg) : "");    sock->write("?<%c>%4c%4c%s", cmd, ++seqno, sizeof(arg), arg);    string res;    int rlen;    if((res = sock->read(12)) && sizeof(res)==12 &&    res[1..7]==sprintf("<%c>%4c", cmd, seqno) &&    sscanf(res[8..11], "%4c", rlen)==1 && (res[0]=='.' || res[0]=='!')) {    mixed rdat = (rlen? sock->read(rlen) : "");    if((!rdat) || sizeof(rdat)!=rlen) {    destruct(sock);    UNLOCK;    if(noreconnect)    ERROR("RSQL Phase error, disconnected\n"); -  else return do_request(cmd, arg, 1); +  else return do_request(cmd, arg);    }    UNLOCK;    rdat = (sizeof(rdat)? decode_value(rdat):0);    switch(res[0]) {    case '.': return rdat;    case '!': ERROR(rdat);    }    ERROR("Internal error\n");    } else {    destruct(sock);    UNLOCK;    if(noreconnect) -  ERROR("RSQL Phase error, disconnected\n"); -  else return do_request(cmd, arg, 1); +  ERROR("RSQL connection closed\n"); +  else return do_request(cmd, arg);    }   }    - void select_db(string db) + protected mixed do_proxy(string cmd, array(mixed) args)   { -  do_request('D', db); +  return do_request('P', ({ cmd, args }));   }    -  + void select_db(string the_db) + { +  do_request('D', the_db); +  db = the_db; + } +    int|string error()   {    return do_request('E');   }      void create_db(string db)   {    do_request('C', db);   }   
pike.git/lib/modules/Sql.pmod/rsql.pike:135:   string host_info()   {    return do_request('i');   }      void shutdown()   {    do_request('s');   }    + int ping() + { +  catch { +  return do_request('p', UNDEFINED, 1); +  }; +  catch { +  if (do_request('p') >= 0) return 1; +  }; +  return -1; + } +    void reload()   {    do_request('r');   }      array(string) list_dbs(string|void wild)   {    return do_request('l', wild);   }   
pike.git/lib/modules/Sql.pmod/rsql.pike:160:   array(mapping(string:mixed)) list_fields(string ... args)   {    return do_request('f', args);   }      string quote(string s)   {    return do_request('q');   }    - int|object big_query(object|string q, mapping(string|int:mixed)|void bindings) + protected class RemoteResult(protected function(int,mixed:mixed) do_request, +  protected mixed qid)   { -  if(bindings) -  q=.sql_util.emulate_bindings(q,bindings,this); -  -  mixed qid = do_request('Q', q); -  return qid && class { -  -  protected function(int,mixed:mixed) do_request; -  protected mixed qid; -  +     void destroy()    {    do_request('Z', qid);    }       int|array(string|int) fetch_row()    {    return do_request('R', qid);    }   
pike.git/lib/modules/Sql.pmod/rsql.pike:205:       int eof()    {    return do_request('e', qid);    }       void seek(int skip)    {    do_request('S', ({qid,skip}));    } + }    -  void create(function(int,mixed:mixed) d_r, mixed i) + int|object big_query(object|string q, mapping(string|int:mixed)|void bindings)   { -  do_request = d_r; -  qid = i; +  if(bindings) +  q=.sql_util.emulate_bindings(q,bindings,this); +  +  mixed qid = do_request('Q', q); +  return qid && RemoteResult(do_request, qid);   }    -  }(do_request, qid); + int|object big_typed_query(object|string q, +  mapping(string|int:mixed)|void bindings) + { +  if(bindings) +  q=.sql_util.emulate_bindings(q,bindings,this); +  +  mixed qid = do_request('Q', ({ "big_typed_query", q })); +  return qid && RemoteResult(do_request, qid);   }    -  + int|object streaming_query(object|string q, +  mapping(string|int:mixed)|void bindings) + { +  if(bindings) +  q=.sql_util.emulate_bindings(q,bindings,this); +  +  mixed qid = do_request('Q', ({ "streaming_query", q })); +  return qid && RemoteResult(do_request, qid); + } +  + int|object streaming_typed_query(object|string q, +  mapping(string|int:mixed)|void bindings) + { +  if(bindings) +  q=.sql_util.emulate_bindings(q,bindings,this); +  +  mixed qid = do_request('Q', ({ "streaming_typed_query", q })); +  return qid && RemoteResult(do_request, qid); + } +    array(mapping(string:mixed)) query(mixed ... args)   {    return do_request('@', args);   }    -  + int insert_id() + { +  return do_request('#'); + } +  + string get_charset() + { +  return do_request('h'); + } +  + void set_charset(string charset) + { +  do_request('H', charset); + } +  + protected function|mixed `->(string cmd) + { +  return ::`->(cmd) || +  lambda(mixed ... args) { +  return do_proxy(cmd, args); +  }; + } +    void create(string|void host, string|void db, string|void user,    string|void _pw, mapping|void options)   {    string pw = _pw;    _pw = "CENSORED";       // Reconstruct the original URL (minus rsql://)       if(!host) {    destruct(this);