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

version» Context lines:

pike.git/lib/modules/Sql.pmod/tds.pike:1:   /* -  * $Id: tds.pike,v 1.12 2006/02/14 16:19:34 grubba Exp $ +  * $Id: tds.pike,v 1.13 2006/02/15 13:15:44 grubba Exp $    *    * A Pike implementation of the TDS protocol.    *    * Henrik Grubbström 2006-02-08.    */      /* #define TDS_DEBUG */   /* #define TDS_CONVERT_DEBUG */      #ifdef TDS_DEBUG
pike.git/lib/modules/Sql.pmod/tds.pike:229:    {    if (done) {    TDS_WERROR("Filling buffer on finished packet!\n"    "%s\n", hex_dump(inbuf));    tds_error("Filling buffer on finished packet!\n");    }       string header = socket->read(8);    if (!header || sizeof(header) < 8) {    busy = !(done = 1); +  int errno = socket->errno(); +  Disconnect();    tds_error("Failed to read packet header: %O, %s.\n", -  header, strerror(socket->errno())); +  header, strerror(errno));    }    TDS_WERROR("Read header:\n%s\n", hex_dump(header));    int packet_type;    int last_packet;    int len;    // NOTE: Network byteorder!!    sscanf(header, "%-1c%-1c%2c", packet_type, last_packet, len);    len -= 8;       busy = !(done = last_packet);
pike.git/lib/modules/Sql.pmod/tds.pike:468:    array(string) packets = ((string) p)/32768.0;    foreach(packets; int i; string raw) {    // NOTE: Network byteorder!!    raw = sprintf("%1c%1c%2c\0\0%1c\0%s",    flag, (i == (sizeof(packets)-1)) && last,    sizeof(raw) + 8,    1, /* TDS 7 or 8. */    raw);    TDS_WERROR("Wrapped packet: %O\n%s\n", raw, hex_dump(raw));    if (socket->write(raw) != sizeof(raw)) { -  socket->close(); -  socket = 0; +  Disconnect();    tds_error("Failed to send packet.\n"    "raw: %O\n", raw);    }    }    //Stdio.write_file("packet.bin", raw);    if (last) return InPacket();    return 0;    }       static string crypt_pass(string password)
pike.git/lib/modules/Sql.pmod/tds.pike:1346:    }    }       object(Connection) con;       int affected_rows;    string server_product_name = "";       int busy;    -  void Disconnect() +  void Disconnect(int|void keep_alive)    {    con->disconnect();    con = 0; -  +  if (!keep_alive) { +  destruct();    } -  +  }       void Connect(string server, int port, string database,    string uid, string password)    {    con = Connection(server, port, database, uid, password);    }      #if (__REAL_MAJOR__ > 7) || ((__REAL_MAJOR__ == 7) && (__REAL_MINOR__ >= 6))   };   #endif /* Pike 7.6 or later */
pike.git/lib/modules/Sql.pmod/tds.pike:1610:   //! Password to access with.   //!   //! Usually accessed via @[Sql.Sql()].   //!   //! @seealso   //! @[Sql.Sql()]   static void create(string|void server, string|void database,    string|void user, string|void password)   {    if (con) { -  Disconnect(); +  Disconnect(1);    }    int port = DEF_PORT;    if (server) {    array(string) tmp = server/":";    if (sizeof(tmp) > 1) {    port = (int)tmp[-1];    server = tmp[..sizeof(tmp)-2]*":";    }    } else {    server = "127.0.0.1";    }    Connect(server, port, database || "default",    user || "", password || "");   }