cvs: pear /DB_DBA DBA_Sql.php /DB_DBA/tests test_sql.php
| From: | Brent Cook | Date: | Tue, 09 Jul 2002 23:35:42 +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-4995@lists.php.net to get a copy of this message | ||
busterb Tue Jul 9 19:35:42 2002 EDT
Modified files:
/pear/DB_DBA DBA_Sql.php
/pear/DB_DBA/tests test_sql.php
Log:
fix the corner case of quoted single words
Index: pear/DB_DBA/DBA_Sql.php
diff -u pear/DB_DBA/DBA_Sql.php:1.5 pear/DB_DBA/DBA_Sql.php:1.6
--- pear/DB_DBA/DBA_Sql.php:1.5 Tue Jul 9 15:25:32 2002
+++ pear/DB_DBA/DBA_Sql.php Tue Jul 9 19:35:42 2002
@@ -18,7 +18,7 @@
// | Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA|
// +----------------------------------------------------------------------+
//
-// $Id: DBA_Sql.php,v 1.5 2002/07/09 19:25:32 busterb Exp $
+// $Id: DBA_Sql.php,v 1.6 2002/07/09 23:35:42 busterb Exp $
//
require_once "PEAR.php";
@@ -41,11 +41,15 @@
function getString() {
$string = strtok(" \n\t");
- echo $string;
$quote = substr($string, 0, 1);
if (($quote != '"') && ($quote != "'")) {
// this was not quoted, just return the token
return $string;
+ } elseif ((substr($string, -1) == $quote) &&
+ (substr($string, -2) != "\\$quote") &&
+ (strlen($string) > 1)) {
+ // corner case of a single quoted word
+ return substr($string, 1, -1);
} else {
// strip the first quote
$string = substr($string, 1).' ';
@@ -73,7 +77,7 @@
$token = DBA_Sql::getToken();
if ($token != '(') {
return PEAR::raiseError(
- "Parse error at $token on $rawquery");
+ "No field definitions found in table $tableName");
exit;
} else {
while ($token && ($token != ')')) {
@@ -83,10 +87,9 @@
$token = strtolower(DBA_Sql::getToken());
// parse field-specific parameters
switch ($fieldType) {
- case 'int':
- case 'integer':
- case 'float':
- case 'numeric':
+ case 'int': case 'integer': case 'float':
+ case 'numeric': case 'bigint': case 'littleint':
+ case 'tinyint':
if ($token == '(') {
$tables[$tableName][$fieldName]['size'] =
DBA_Sql::getToken();
@@ -98,7 +101,7 @@
}
if ($token != ')') {
return PEAR::raiseError(
- "Parse error at $token on $rawquery");
+ "Parse error $token on $rawquery");
}
$token = DBA_Sql::getToken();
}
Index: pear/DB_DBA/tests/test_sql.php
diff -u pear/DB_DBA/tests/test_sql.php:1.5 pear/DB_DBA/tests/test_sql.php:1.6
--- pear/DB_DBA/tests/test_sql.php:1.5 Tue Jul 9 15:25:33 2002
+++ pear/DB_DBA/tests/test_sql.php Tue Jul 9 19:35:42 2002
@@ -20,7 +20,7 @@
// | Author: Brent Cook <busterb@mail.utexas.edu> |
// +----------------------------------------------------------------------+
//
-// $Id: test_sql.php,v 1.5 2002/07/09 19:25:33 busterb Exp $
+// $Id: test_sql.php,v 1.6 2002/07/09 23:35:42 busterb Exp $
//
// test functionality of the sql parser
@@ -29,6 +29,8 @@
require_once '../DBA_Sql.php';
$queries = array(
+"create table nodefinitions",
+"create dogfood",
"CREATE TABLE albums (
name varchar(60),
directory varchar(60),
@@ -43,7 +45,7 @@
name varchar(60) default \"no name\",
album int,
price float (4,2),
- description text,
+ description text default 'hello',
id int
)"
@@ -51,12 +53,13 @@
foreach ($queries as $query) {
$results = DBA_Sql::parseCreate($query);
- echo $query;
+ echo $query."\n";
if (PEAR::isError($results)) {
echo $results->getMessage()."\n";
} else {
print_r($results);
}
+ echo "\n***********************************\n\n";
}
?>