cvs: pear /DB_DBA DBA_Sql.php /DB_DBA/tests test_sql.php

From: Date: Tue, 09 Jul 2002 19:17:39 +0000
Subject: cvs: pear /DB_DBA DBA_Sql.php /DB_DBA/tests test_sql.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-4993@lists.php.net to get a copy of this message
busterb Tue Jul 9 15:17:39 2002 EDT Modified files: /pear/DB_DBA DBA_Sql.php /pear/DB_DBA/tests test_sql.php Log: now understands quoted strings Index: pear/DB_DBA/DBA_Sql.php diff -u pear/DB_DBA/DBA_Sql.php:1.3 pear/DB_DBA/DBA_Sql.php:1.4 --- pear/DB_DBA/DBA_Sql.php:1.3 Tue Jul 9 14:44:33 2002 +++ pear/DB_DBA/DBA_Sql.php Tue Jul 9 15:17:38 2002 @@ -18,7 +18,7 @@ // | Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA| // +----------------------------------------------------------------------+ // -// $Id: DBA_Sql.php,v 1.3 2002/07/09 18:44:33 busterb Exp $ +// $Id: DBA_Sql.php,v 1.4 2002/07/09 19:17:38 busterb Exp $ // require_once "PEAR.php"; @@ -29,7 +29,7 @@ // adds spaces around special characters function cookQuery($query) { - foreach (array(',','(',')','"',"'") as $symbol) { + foreach (array(',','(',')',"\'") as $symbol) { $query = str_replace($symbol, " $symbol ", $query); } return $query; @@ -40,11 +40,22 @@ } function getString() { - $token = strtok(" \n\t"); - if (($token != '"') && ($token != "'")) { - return $token; + $string = strtok(" \n\t"); + $quote = substr($string, 0, 1); + if (($quote != '"') && ($quote != "'")) { + // this was not quoted, just return the token + return $string; } else { - return strtok($token); + // strip the first quote + $string = substr($string, 1).' '; + // read until the next quote + $string .= strtok($quote); + // was this an escaped quote? + while (substr($string, -1) == "\\") { + // insert the quote, keep reading + $string = substr($string,0,-2).$quote.substr(strtok($quote), 1); + } + return $string; } } Index: pear/DB_DBA/tests/test_sql.php diff -u pear/DB_DBA/tests/test_sql.php:1.3 pear/DB_DBA/tests/test_sql.php:1.4 --- pear/DB_DBA/tests/test_sql.php:1.3 Tue Jul 9 14:44:33 2002 +++ pear/DB_DBA/tests/test_sql.php Tue Jul 9 15:17:39 2002 @@ -20,7 +20,7 @@ // | Author: Brent Cook <busterb@mail.utexas.edu> | // +----------------------------------------------------------------------+ // -// $Id: test_sql.php,v 1.3 2002/07/09 18:44:33 busterb Exp $ +// $Id: test_sql.php,v 1.4 2002/07/09 19:17:39 busterb Exp $ // // test functionality of the sql parser @@ -33,7 +33,7 @@ name varchar(60), directory varchar(60), rating enum (1,2,3,4,5,6,7,8,9,10) NOT NULL, - category set(sexy,family,outdoors,generic,'very weird') NULL, + category set(sexy,'\'family time\'',outdoors,generic,'very weird') NULL, description text NULL, id int auto_increment default 200 )", @@ -51,6 +51,7 @@ foreach ($queries as $query) { $results = DBA_Sql::parseCreate($query); + echo $query; if (PEAR::isError($results)) { echo $results->getMessage()."\n"; } else {

« previous php.pear.cvs (#4993) next »