]> granicus.if.org Git - php/commitdiff
- mysql_affected_rows() already returns an unsigned long
authorAndrey Hristov <andrey@php.net>
Mon, 11 Jul 2005 13:52:13 +0000 (13:52 +0000)
committerAndrey Hristov <andrey@php.net>
Mon, 11 Jul 2005 13:52:13 +0000 (13:52 +0000)
- optimize a bit the real_escape
- handle the situation when libmysql bails out because of lack of memory

ext/pdo_mysql/mysql_driver.c

index 538cf0972569c8468d753cd21baa0211f73a9b56..6002468401e10cd4ac887f6d0bbaf10beb1cae70 100755 (executable)
@@ -225,8 +225,7 @@ static long mysql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRM
                pdo_mysql_error(dbh);
                return -1;
        } else {
-               long c = mysql_affected_rows(H->server);
-               return c >0 ? c : 0;
+               return mysql_affected_rows(H->server);
        }
 }
 
@@ -242,11 +241,9 @@ static int mysql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquote
 {
        pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
        *quoted = emalloc(2*unquotedlen + 3);
-       (*quoted)[0] = '"';
        *quotedlen = mysql_real_escape_string(H->server, *quoted + 1, unquoted, unquotedlen);
-       (*quoted)[*quotedlen + 1] = '"';
-       (*quoted)[*quotedlen + 2] = '\0';
-       *quotedlen += 2;
+       (*quoted)[0] =(*quoted)[*quotedlen + 1] = '"';
+       (*quoted)[*quotedlen+=2] = '\0';
        return 1;
 }
 
@@ -329,7 +326,7 @@ static int pdo_mysql_get_attribute(pdo_dbh_t *dbh, long attr, zval *return_value
                case PDO_ATTR_AUTOCOMMIT:
                        ZVAL_LONG(return_value, dbh->auto_commit);
                        return 1;
-
+                       
                case PDO_MYSQL_ATTR_USE_BUFFERED_QUERY:
                        ZVAL_LONG(return_value, H->buffered);
                        return 1;
@@ -398,7 +395,11 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_
        /* allocate an environment */
        
        /* handle for the server */
-       H->server = mysql_init(NULL);
+       if (!(H->server = mysql_init(NULL))) {
+               pdo_mysql_error(dbh);
+               goto cleanup;
+       }
+       
        dbh->driver_data = H;
 
        /* handle MySQL options */