cvs: pear /SQL_Parser/tests generate_testcases.php select.php

From: Date: Wed, 18 Dec 2002 03:19:50 +0000
Subject: cvs: pear /SQL_Parser/tests generate_testcases.php select.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-7921@lists.php.net to get a copy of this message
busterb Tue Dec 17 22:19:50 2002 EDT Modified files: /pear/SQL_Parser/tests generate_testcases.php select.php Log: update select testcases Index: pear/SQL_Parser/tests/generate_testcases.php diff -u pear/SQL_Parser/tests/generate_testcases.php:1.1 pear/SQL_Parser/tests/generate_testcases.php:1.2 --- pear/SQL_Parser/tests/generate_testcases.php:1.1 Tue Sep 24 13:06:58 2002 +++ pear/SQL_Parser/tests/generate_testcases.php Tue Dec 17 22:19:50 2002 @@ -20,14 +20,13 @@ // | Author: Brent Cook <busterb@mail.utexas.edu> | // +----------------------------------------------------------------------+ // -// $Id: generate_testcases.php,v 1.1 2002/09/24 17:06:58 busterb Exp $ +// $Id: generate_testcases.php,v 1.2 2002/12/18 03:19:50 busterb Exp $ // // test functionality of the sql parser require_once 'PEAR.php'; -require_once 'DB/DBA/Sql_parse.php'; -require_once 'Console/Getopt.php'; +require_once 'SQL/Parser.php'; // based on DataDumper by Matt Durell <matt@specialsource.net> function dump($input, $tab = "\t", $newline = "\n", @@ -70,22 +69,13 @@ $progname = basename(array_shift($argv)); -$options = Console_Getopt::getopt($argv, "f:"); -if (PEAR::isError($options)) { - usage($options); +echo(count($argv)); +if (count($argv) != 2) { + echo("Usage: generate_testcases.php test_cases.sql\n"); + exit(-1); } -$opts = $options[0]; -foreach ($opts as $opt) { - switch ($opt[0]) { - case 'f': - $file = $opt[1]; - break; - default: - echo "Unknown option :".$opt[0]; - exit; - } -} +$file = $argv[1]; if (!$fd = @fopen($file, 'r')) { echo("Could not load the SQL source file: $file\n"); Index: pear/SQL_Parser/tests/select.php diff -u pear/SQL_Parser/tests/select.php:1.1 pear/SQL_Parser/tests/select.php:1.2 --- pear/SQL_Parser/tests/select.php:1.1 Tue Sep 24 13:06:58 2002 +++ pear/SQL_Parser/tests/select.php Tue Dec 17 22:19:50 2002 @@ -1,4 +1,4 @@ -<?php +2<?php $tests = array( array( 'sql' => 'select * from dog where cat <> 4', @@ -10,6 +10,9 @@ 'table_names' => array( 0 => 'dog' ), + 'table_aliases' => array( + 0 => '' + ), 'where_clause' => array( 'arg_1' => array( 'value' => 'cat', @@ -27,12 +30,23 @@ 'sql' => 'select legs, hairy from dog', 'expect' => array( 'command' => 'select', + 'column_tables' => array( + 0 => '', + 1 => '' + ), 'column_names' => array( 0 => 'legs', 1 => 'hairy' ), + 'column_aliases' => array( + 0 => '', + 1 => '' + ), 'table_names' => array( 0 => 'dog' + ), + 'table_aliases' => array( + 0 => '' ) ) ), @@ -46,6 +60,9 @@ ), 'table_names' => array( 0 => 'dog' + ), + 'table_aliases' => array( + 0 => '' ) ) ), @@ -60,6 +77,9 @@ ), 'table_names' => array( 0 => 'publishers' + ), + 'table_aliases' => array( + 0 => '' ) ) ), @@ -67,13 +87,24 @@ 'sql' => 'select one, two from hairy where two <> 4 and one = 2', 'expect' => array( 'command' => 'select', + 'column_tables' => array( + 0 => '', + 1 => '' + ), 'column_names' => array( 0 => 'one', 1 => 'two' ), + 'column_aliases' => array( + 0 => '', + 1 => '' + ), 'table_names' => array( 0 => 'hairy' ), + 'table_aliases' => array( + 0 => '' + ), 'where_clause' => array( 'arg_1' => array( 'arg_1' => array( @@ -105,13 +136,24 @@ 'sql' => 'select one, two from hairy where two <> 4 and one = 2 order by two', 'expect' => array( 'command' => 'select', + 'column_tables' => array( + 0 => '', + 1 => '' + ), 'column_names' => array( 0 => 'one', 1 => 'two' ), + 'column_aliases' => array( + 0 => '', + 1 => '' + ), 'table_names' => array( 0 => 'hairy' ), + 'table_aliases' => array( + 0 => '' + ), 'where_clause' => array( 'arg_1' => array( 'arg_1' => array( @@ -146,13 +188,24 @@ 'sql' => 'select one, two from hairy where two <> 4 and one = 2 limit 4 order by two ascending, dog descending', 'expect' => array( 'command' => 'select', + 'column_tables' => array( + 0 => '', + 1 => '' + ), 'column_names' => array( 0 => 'one', 1 => 'two' ), + 'column_aliases' => array( + 0 => '', + 1 => '' + ), 'table_names' => array( 0 => 'hairy' ), + 'table_aliases' => array( + 0 => '' + ), 'where_clause' => array( 'arg_1' => array( 'arg_1' => array( @@ -185,6 +238,69 @@ 'sort_order' => array( 'two' => 'asc', 'dog' => 'desc' + ) + ) +), +array( +'sql' => 'select foo.a from foo', +'expect' => array( + 'command' => 'select', + 'column_tables' => array( + 0 => 'foo' + ), + 'column_names' => array( + 0 => 'a' + ), + 'column_aliases' => array( + 0 => '' + ), + 'table_names' => array( + 0 => 'foo' + ), + 'table_aliases' => array( + 0 => '' + ) + ) +), +array( +'sql' => 'select a as b from foo', +'expect' => array( + 'command' => 'select', + 'column_tables' => array( + 0 => '' + ), + 'column_names' => array( + 0 => 'a' + ), + 'column_aliases' => array( + 0 => 'b' + ), + 'table_names' => array( + 0 => 'foo' + ), + 'table_aliases' => array( + 0 => '' + ) + ) +), +array( +'sql' => 'select a from foo as bar', +'expect' => array( + 'command' => 'select', + 'column_tables' => array( + 0 => '' + ), + 'column_names' => array( + 0 => 'a' + ), + 'column_aliases' => array( + 0 => '' + ), + 'table_names' => array( + 0 => 'foo' + ), + 'table_aliases' => array( + 0 => 'bar' ) ) ),

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