0e5f502017-11-22Stephen R. van den Berg #pike __REAL_VERSION__
886f062017-11-24Stephen R. van den Berg //#define SP_DEBUG 1 //#define SP_DEBUGMORE 1
0e5f502017-11-22Stephen R. van den Berg  #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
23fa712017-11-24Stephen R. van den Berg //! The promise result class; it will contain the results of a query. //! //! @seealso //! @[Promise], @[Connection.promise_query()]
0e5f502017-11-22Stephen R. van den Berg  //! The returned raw unadorned records, all typed data.
964a422017-11-25Stephen R. van den Berg //! Once @[get()] has been accessed, @[data]
0e5f502017-11-22Stephen R. van den Berg //! will point to the same adorned records. //! //! @seealso //! @[Sql.Connection->big_typed_query()]
964a422017-11-25Stephen R. van den Berg final array(mixed) data;
0e5f502017-11-22Stephen R. van den Berg 
964a422017-11-25Stephen R. van den Berg //! @returns
0e5f502017-11-22Stephen R. van den Berg //! The returned labeled records, all typed data. //! //! @seealso
964a422017-11-25Stephen R. van den Berg //! @[Sql.Connection->query()], @[data] final array(mapping(string:mixed)) get() {
886f062017-11-24Stephen R. van den Berg  if (_dblink) {
964a422017-11-25Stephen R. van den Berg  data = _dblink->res_obj_to_array(data, fields);
886f062017-11-24Stephen R. van den Berg  _dblink = 0;
0e5f502017-11-22Stephen R. van den Berg  }
964a422017-11-25Stephen R. van den Berg  return data;
0e5f502017-11-22Stephen R. van den Berg } //! The SQL query. final string query; //! The parameter bindings belonging to the query. final mapping(string:mixed) bindings;
33bf722017-11-23Stephen R. van den Berg //! 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;
0e5f502017-11-22Stephen R. van den Berg  //! The number of affected rows. final int affected_rows; //! The description of the fields in a record. final array(mapping(string:mixed)) fields;
886f062017-11-24Stephen R. van den Berg final .Connection _dblink;
0e5f502017-11-22Stephen R. van den Berg  protected string _sprintf(int type) { string res; switch(type) { case 'O':
85d1892019-04-26Stephen R. van den Berg  res = status_command_complete && arrayp(status_command_complete) ? status_command_complete[0] : sprintf("FutureResult from query: %O, bindings: %O\n" "recordcount: %d\nSQL status: %s", query, bindings, sizeof(data), status_command_complete || "still running...");
0e5f502017-11-22Stephen R. van den Berg  break; } return res; }
886f062017-11-24Stephen R. van den Berg protected void create(.Connection db, string q, mapping(string:mixed) bindings) { PD("Create future result %O %O %O\n", db, q, bindings);
0e5f502017-11-22Stephen R. van den Berg  query = q; this::bindings = bindings;
964a422017-11-25Stephen R. van den Berg  data = ({});
886f062017-11-24Stephen R. van den Berg  _dblink = db;
0e5f502017-11-22Stephen R. van den Berg }
886f062017-11-24Stephen R. van den Berg #ifdef SP_DEBUG
0e5f502017-11-22Stephen R. van den Berg protected void _destruct() {
886f062017-11-24Stephen R. van den Berg  PD("Destroy result %O %O\n", query, bindings);
0e5f502017-11-22Stephen R. van den Berg }
886f062017-11-24Stephen R. van den Berg #endif