Diff for /embedaddon/php/ext/pdo_pgsql/pgsql_driver.c between versions 1.1.1.1 and 1.1.1.5

version 1.1.1.1, 2012/02/21 23:47:59 version 1.1.1.5, 2014/06/15 20:03:53
Line 2 Line 2
   +----------------------------------------------------------------------+    +----------------------------------------------------------------------+
   | PHP Version 5                                                        |    | PHP Version 5                                                        |
   +----------------------------------------------------------------------+    +----------------------------------------------------------------------+
  | Copyright (c) 1997-2012 The PHP Group                                |  | Copyright (c) 1997-2014 The PHP Group                                |
   +----------------------------------------------------------------------+    +----------------------------------------------------------------------+
   | This source file is subject to version 3.01 of the PHP license,      |    | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |    | that is bundled with this package in the file LICENSE, and is        |
Line 76  int _pdo_pgsql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, Line 76  int _pdo_pgsql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt,
                 einfo->errmsg = NULL;                  einfo->errmsg = NULL;
         }          }
   
        if (sqlstate == NULL) {        if (sqlstate == NULL || strlen(sqlstate) >= sizeof(pdo_error_type)) {
                 strcpy(*pdo_err, "HY000");                  strcpy(*pdo_err, "HY000");
         }          }
         else {          else {
Line 299  static long pgsql_handle_doer(pdo_dbh_t *dbh, const ch Line 299  static long pgsql_handle_doer(pdo_dbh_t *dbh, const ch
                 return -1;                  return -1;
         }          }
         H->pgoid = PQoidValue(res);          H->pgoid = PQoidValue(res);
        ret = atol(PQcmdTuples(res));        ret = (qs == PGRES_COMMAND_OK) ? atol(PQcmdTuples(res)) : 0L;
         PQclear(res);          PQclear(res);
   
         return ret;          return ret;
Line 315  static int pgsql_handle_quoter(pdo_dbh_t *dbh, const c Line 315  static int pgsql_handle_quoter(pdo_dbh_t *dbh, const c
                 case PDO_PARAM_LOB:                  case PDO_PARAM_LOB:
                         /* escapedlen returned by PQescapeBytea() accounts for trailing 0 */                          /* escapedlen returned by PQescapeBytea() accounts for trailing 0 */
 #ifdef HAVE_PQESCAPE_BYTEA_CONN  #ifdef HAVE_PQESCAPE_BYTEA_CONN
                        escaped = PQescapeByteaConn(H->server, unquoted, unquotedlen, &tmp_len);                        escaped = PQescapeByteaConn(H->server, (unsigned char *)unquoted, (size_t)unquotedlen, &tmp_len);
 #else  #else
                        escaped = PQescapeBytea(unquoted, unquotedlen, &tmp_len);                        escaped = PQescapeBytea((unsigned char *)unquoted, (size_t)unquotedlen, &tmp_len);
 #endif  #endif
                         *quotedlen = (int)tmp_len + 1;                          *quotedlen = (int)tmp_len + 1;
                         *quoted = emalloc(*quotedlen + 1);                          *quoted = emalloc(*quotedlen + 1);
Line 331  static int pgsql_handle_quoter(pdo_dbh_t *dbh, const c Line 331  static int pgsql_handle_quoter(pdo_dbh_t *dbh, const c
                         *quoted = safe_emalloc(2, unquotedlen, 3);                          *quoted = safe_emalloc(2, unquotedlen, 3);
                         (*quoted)[0] = '\'';                          (*quoted)[0] = '\'';
 #ifndef HAVE_PQESCAPE_CONN  #ifndef HAVE_PQESCAPE_CONN
                        *quotedlen = PQescapeString(*quoted + 1, unquoted, unquotedlen);                        *quotedlen = PQescapeString(*quoted + 1, unquoted, (size_t)unquotedlen);
 #else  #else
                        *quotedlen = PQescapeStringConn(H->server, *quoted + 1, unquoted, unquotedlen, NULL);                        *quotedlen = PQescapeStringConn(H->server, *quoted + 1, unquoted, (size_t)unquotedlen, NULL);
 #endif  #endif
                         (*quoted)[*quotedlen + 1] = '\'';                          (*quoted)[*quotedlen + 1] = '\'';
                         (*quoted)[*quotedlen + 2] = '\0';                          (*quoted)[*quotedlen + 2] = '\0';
Line 497  static int pgsql_handle_rollback(pdo_dbh_t *dbh TSRMLS Line 497  static int pgsql_handle_rollback(pdo_dbh_t *dbh TSRMLS
         return pdo_pgsql_transaction_cmd("ROLLBACK", dbh TSRMLS_CC);          return pdo_pgsql_transaction_cmd("ROLLBACK", dbh TSRMLS_CC);
 }  }
   
   static int pgsql_handle_in_transaction(pdo_dbh_t *dbh TSRMLS_DC)
   {
           pdo_pgsql_db_handle *H;
   
           H = (pdo_pgsql_db_handle *)dbh->driver_data;
   
           return PQtransactionStatus(H->server);
   }
   
 /* {{{ proto string PDO::pgsqlCopyFromArray(string $table_name , array $rows [, string $delimiter [, string $null_as ] [, string $fields])  /* {{{ proto string PDO::pgsqlCopyFromArray(string $table_name , array $rows [, string $delimiter [, string $null_as ] [, string $fields])
    Returns true if the copy worked fine or false if error */     Returns true if the copy worked fine or false if error */
 static PHP_METHOD(PDO, pgsqlCopyFromArray)  static PHP_METHOD(PDO, pgsqlCopyFromArray)
Line 619  static PHP_METHOD(PDO, pgsqlCopyFromFile) Line 628  static PHP_METHOD(PDO, pgsqlCopyFromFile)
         ExecStatusType status;          ExecStatusType status;
         php_stream *stream;          php_stream *stream;
   
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|sss",        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sp|sss",
                                 &table_name, &table_name_len, &filename, &filename_len,                                  &table_name, &table_name_len, &filename, &filename_len,
                                 &pg_delim, &pg_delim_len, &pg_null_as, &pg_null_as_len, &pg_fields, &pg_fields_len) == FAILURE) {                                  &pg_delim, &pg_delim_len, &pg_null_as, &pg_null_as_len, &pg_fields, &pg_fields_len) == FAILURE) {
                 return;                  return;
Line 713  static PHP_METHOD(PDO, pgsqlCopyToFile) Line 722  static PHP_METHOD(PDO, pgsqlCopyToFile)
   
         php_stream *stream;          php_stream *stream;
   
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|sss",        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sp|sss",
                                         &table_name, &table_name_len, &filename, &filename_len,                                          &table_name, &table_name_len, &filename, &filename_len,
                                         &pg_delim, &pg_delim_len, &pg_null_as, &pg_null_as_len, &pg_fields, &pg_fields_len) == FAILURE) {                                          &pg_delim, &pg_delim_len, &pg_null_as, &pg_null_as_len, &pg_fields, &pg_fields_len) == FAILURE) {
                 return;                  return;
Line 1022  static struct pdo_dbh_methods pgsql_methods = { Line 1031  static struct pdo_dbh_methods pgsql_methods = {
         pdo_pgsql_check_liveness,       /* check_liveness */          pdo_pgsql_check_liveness,       /* check_liveness */
         pdo_pgsql_get_driver_methods,  /* get_driver_methods */          pdo_pgsql_get_driver_methods,  /* get_driver_methods */
         NULL,          NULL,
           pgsql_handle_in_transaction,
 };  };
   
 static int pdo_pgsql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_DC) /* {{{ */  static int pdo_pgsql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_DC) /* {{{ */
Line 1029  static int pdo_pgsql_handle_factory(pdo_dbh_t *dbh, zv Line 1039  static int pdo_pgsql_handle_factory(pdo_dbh_t *dbh, zv
         pdo_pgsql_db_handle *H;          pdo_pgsql_db_handle *H;
         int ret = 0;          int ret = 0;
         char *conn_str, *p, *e;          char *conn_str, *p, *e;
           char *tmp_pass;
         long connect_timeout = 30;          long connect_timeout = 30;
   
         H = pecalloc(1, sizeof(pdo_pgsql_db_handle), dbh->is_persistent);          H = pecalloc(1, sizeof(pdo_pgsql_db_handle), dbh->is_persistent);
Line 1050  static int pdo_pgsql_handle_factory(pdo_dbh_t *dbh, zv Line 1061  static int pdo_pgsql_handle_factory(pdo_dbh_t *dbh, zv
                 connect_timeout = pdo_attr_lval(driver_options, PDO_ATTR_TIMEOUT, 30 TSRMLS_CC);                  connect_timeout = pdo_attr_lval(driver_options, PDO_ATTR_TIMEOUT, 30 TSRMLS_CC);
         }          }
   
           if (dbh->password) {
                   if (dbh->password[0] != '\'' && dbh->password[strlen(dbh->password) - 1] != '\'') {
                           char *pwd = dbh->password;
                           int pos = 1;
   
                           tmp_pass = safe_emalloc(2, strlen(dbh->password), 3);
                           tmp_pass[0] = '\'';
   
                           while (*pwd != '\0') {
                                   if (*pwd == '\\' || *pwd == '\'') {
                                           tmp_pass[pos++] = '\\';
                                   }
   
                                   tmp_pass[pos++] = *pwd++;
                           }
   
                           tmp_pass[pos++] = '\'';
                           tmp_pass[pos] = '\0';
                   } else {
                           tmp_pass = dbh->password;
                   }
           }
   
         /* support both full connection string & connection string + login and/or password */          /* support both full connection string & connection string + login and/or password */
         if (dbh->username && dbh->password) {          if (dbh->username && dbh->password) {
                spprintf(&conn_str, 0, "%s user=%s password=%s connect_timeout=%ld", dbh->data_source, dbh->username, dbh->password, connect_timeout);                spprintf(&conn_str, 0, "%s user=%s password=%s connect_timeout=%ld", dbh->data_source, dbh->username, tmp_pass, connect_timeout);
         } else if (dbh->username) {          } else if (dbh->username) {
                 spprintf(&conn_str, 0, "%s user=%s connect_timeout=%ld", dbh->data_source, dbh->username, connect_timeout);                  spprintf(&conn_str, 0, "%s user=%s connect_timeout=%ld", dbh->data_source, dbh->username, connect_timeout);
         } else if (dbh->password) {          } else if (dbh->password) {
                spprintf(&conn_str, 0, "%s password=%s connect_timeout=%ld", dbh->data_source, dbh->password, connect_timeout);                spprintf(&conn_str, 0, "%s password=%s connect_timeout=%ld", dbh->data_source, tmp_pass, connect_timeout);
         } else {          } else {
                 spprintf(&conn_str, 0, "%s connect_timeout=%ld", (char *) dbh->data_source, connect_timeout);                  spprintf(&conn_str, 0, "%s connect_timeout=%ld", (char *) dbh->data_source, connect_timeout);
         }          }
   
         H->server = PQconnectdb(conn_str);          H->server = PQconnectdb(conn_str);
           if (dbh->password && tmp_pass != dbh->password) {
                   efree(tmp_pass);
           }
   
         efree(conn_str);          efree(conn_str);
   

Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.5


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>