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. //! Once @[data] has been accessed, @[raw_data] //! will point to the same adorned records. //! //! @seealso //! @[Sql.Connection->big_typed_query()] final array(mixed) raw_data; //! The returned labeled records, all typed data. //! //! @seealso //! @[Sql.Connection->query()], @[raw_data] final array(mapping(string:mixed)) `data() {
886f062017-11-24Stephen R. van den Berg  if (_dblink) { raw_data = _dblink->res_obj_to_array(raw_data, fields); _dblink = 0;
0e5f502017-11-22Stephen R. van den Berg  } return raw_data; } //! 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': res = sprintf("FutureResult from query: %O, bindings: %O\n"
886f062017-11-24Stephen R. van den Berg  "recordcount: %d", query, bindings, sizeof(raw_data));
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; raw_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