pike.git / lib / modules / __builtin.pmod / Sql.pmod / FutureResult.pike

version» Context lines:

pike.git/lib/modules/__builtin.pmod/Sql.pmod/FutureResult.pike:1:   #pike __REAL_VERSION__      //#define SP_DEBUG 1 + //#define SP_DEBUGMORE 1      #ifdef SP_DEBUG   #define PD(X ...) werror(X)    // PT() puts this in the backtrace   #define PT(X ...) (lambda(object _this){(X);}(this))   #else   #undef SP_DEBUGMORE   #define PD(X ...) 0   #define PT(X ...) (X)   #endif
pike.git/lib/modules/__builtin.pmod/Sql.pmod/FutureResult.pike:33:    }    return raw_data;   }      //! The SQL query.   final string query;      //! The parameter bindings belonging to the query.   final mapping(string:mixed) bindings;    - //! The status of the completed command - final string status_command_complete; + //! The status of the completed command. + //! If the command is still in progress, the value is @expr{null@}. + //! If an error has occurred, it contains the backtrace of that error. + final string|mixed status_command_complete;      //! The number of affected rows.   final int affected_rows;      //! The description of the fields in a record.   final array(mapping(string:mixed)) fields;    - //! The backtrace of the error that occurred. - final mixed exception; -  +    private .Connection dblink;   private int minresults;   private int|Concurrent.Promise promise;      protected string _sprintf(int type) {    string res;    switch(type) {    case 'O':    res = sprintf("FutureResult from query: %O, bindings: %O\n"    "recordcount: %d, truth: %O",    query, bindings, sizeof(raw_data), promise);    break;    }    return res;   }    - private void failed() { + private void failed(mixed msg) {    dblink = 0; // Release reference -  if (!exception) -  exception = ({0, backtrace()}); -  PD("Future failed %O %s\n", query, describe_backtrace(exception)); +  status_command_complete = arrayp(msg) ? msg : ({msg, backtrace()}); +  PD("Future failed %O %s\n", query, describe_backtrace(status_command_complete));    if (intp(promise))    error("Future already determined\n");    else {    Concurrent.Promise p = promise;    promise = -1;    p->failure(this);    }   }      private void succeeded(.Result result) {    PD("Future succeeded %O\n", query); -  exception = +  mixed err =    catch {    fields = result->fetch_fields();    affected_rows = result->affected_rows();    status_command_complete = result->status_command_complete();    }; -  if (exception) -  failed(); +  if (err) +  failed(err);    else if (intp(promise))    error("Future already determined\n");    else {    Concurrent.Promise p = promise;    promise = 1;    p->success(this);    }   }      //! @tt{True@} on success, @tt{false@} otherwise.
pike.git/lib/modules/__builtin.pmod/Sql.pmod/FutureResult.pike:120:    break;    default:    raw_data += rows;    }    else    switch (minresults) {    case 2:    if (sizeof(raw_data))    succeeded(result);    case 1: -  failed(); +  failed("Insufficient number of records returned\n");    break;    case 3:    succeeded(result);    }   }      protected void create(.Connection db, Concurrent.Promise p,    string q, mapping(string:mixed) bindings,    int results) {    PD("Create future %O %O %O\n", db, q, bindings);    query = q;    this::bindings = bindings;    raw_data = ({});    minresults = results;    promise = p;    dblink = db; -  if (exception = catch(db->big_typed_query(q, bindings) +  if (status_command_complete = catch(db->big_typed_query(q, bindings)    ->set_result_array_callback(result_cb))) -  failed(); +  failed(status_command_complete);   }      protected void _destruct() {    PD("Destroy future %O %O\n", query, bindings);    if (objectp(promise)) -  failed(); +  failed("Promise broken\n");   }