thekid Fri Jan 23 21:18:14 2004 EDT
Added files:
/php-src/ext/sybase_ct/tests bug22403.phpt bug6339.phpt skipif.inc
test.inc test_connect.phpt
test_msghandler.phpt test_types.phpt
Log:
- Initial release
http://cvs.php.net/co.php/php-src/ext/sybase_ct/tests/bug22403.phpt?r=1.1&p=1
Index: php-src/ext/sybase_ct/tests/bug22403.phpt
+++ php-src/ext/sybase_ct/tests/bug22403.phpt
--TEST--
Sybase-CT bug #22403 (crash when executing a stored procedure without parameters)
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
/* This file is part of PHP test framework for ext/sybase_ct
*
* $Id: bug22403.phpt,v 1.1 2004/01/24 02:18:13 thekid Exp $
*/
require('test.inc');
$db= sybase_connect_ex();
sybase_set_message_handler('sybase_msg_handler');
error_reporting(error_reporting() & !E_NOTICE); // Suppress notices
// Check if stored procedure already exists
$sp_name= basename(__FILE__, '.php');
var_dump(sybase_select_db('tempdb', $db));
if (!sybase_select_single($db, 'select object_id("'.$sp_name.'")')) {
echo "Stored procedure {$sp_name} not found, creating\n";
var_dump(sybase_query('
create proc '.$sp_name.' (@param int)
as
begin
select @param
select @param + 1
return @param
end
'));
} else {
echo "Stored procedure {$sp_name} found, using\n";
var_dump(TRUE);
}
// These don't work
var_dump(sybase_select_ex($db, 'exec '.$sp_name));
var_dump(sybase_select_ex($db, 'exec '.$sp_name.' "foo"'));
var_dump(sybase_select_ex($db, 'exec does_not_exist'));
// These do
var_dump(sybase_select_ex($db, 'exec '.$sp_name.' NULL'));
var_dump(sybase_select_ex($db, 'exec '.$sp_name.' 1'));
// Clean up after ourselves
var_dump(sybase_query('drop proc '.$sp_name));
sybase_close($db);
?>
--EXPECTF--
bool(true)
Stored procedure %s
bool(true)
>>> Query: exec %s
*** Caught Sybase Server Message #201 [Severity 16, state 2] at line 0
%s
<<< Return: boolean
bool(false)
>>> Query: exec %s "foo"
*** Caught Sybase Server Message #257 [Severity 16, state 1] at line 0
%s
<<< Return: boolean
bool(false)
>>> Query: exec does_not_exist
*** Caught Sybase Server Message #2812 [Severity 16, state 4] at line 1
%s
<<< Return: boolean
bool(false)
>>> Query: exec %s NULL
<<< Return: resource
array(1) {
[0]=>
array(1) {
["computed"]=>
NULL
}
}
>>> Query: exec %s 1
<<< Return: resource
array(1) {
[0]=>
array(1) {
["computed"]=>
int(1)
}
}
bool(true)
http://cvs.php.net/co.php/php-src/ext/sybase_ct/tests/bug6339.phpt?r=1.1&p=1
Index: php-src/ext/sybase_ct/tests/bug6339.phpt
+++ php-src/ext/sybase_ct/tests/bug6339.phpt
--TEST--
Sybase-CT bug #6339 (invalid Sybase-link resource)
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
/* This file is part of PHP test framework for ext/sybase_ct
*
* $Id: bug6339.phpt,v 1.1 2004/01/24 02:18:13 thekid Exp $
*/
require('test.inc');
// Suppress "Changed database context" warnings
sybase_min_server_severity(11);
sybase_connect(HOST, USER, PASSWORD);
var_dump(sybase_fetch_row(sybase_query('select 1')));
sybase_close();
?>
--EXPECTF--
array(1) {
[0]=>
int(1)
}
http://cvs.php.net/co.php/php-src/ext/sybase_ct/tests/skipif.inc?r=1.1&p=1
Index: php-src/ext/sybase_ct/tests/skipif.inc
+++ php-src/ext/sybase_ct/tests/skipif.inc
<?php
/* This file is part of PHP test framework for ext/sybase_ct
*
* $Id: skipif.inc,v 1.1 2004/01/24 02:18:13 thekid Exp $
*/
if (!extension_loaded('sybase_ct')) die('Sybase-CT extension not loaded');
?>
http://cvs.php.net/co.php/php-src/ext/sybase_ct/tests/test.inc?r=1.1&p=1
Index: php-src/ext/sybase_ct/tests/test.inc
+++ php-src/ext/sybase_ct/tests/test.inc
<?php
/* This file is part of PHP test framework for ext/sybase_ct
*
* $Id: test.inc,v 1.1 2004/01/24 02:18:13 thekid Exp $
*/
// Change if needed
define('HOST', 'php3');
define('USER', 'news');
define('PASSWORD', 'stuemper');
// {{{ bool sybase_msg_handler(int msgnumber, int severity, int state, int line,
string text)
// Handles server messages
function sybase_msg_handler($msgnumber, $severity, $state, $line, $text) {
printf(
"*** Caught Sybase Server Message #%d [Severity %d, state %d] at line %d\n
'%s'\n",
$msgnumber,
$severity,
$state,
$line,
chop($text)
);
}
// }}}
// {{{ public class sybase
class sybase {
// {{{ public static bool static_handler(int msgnumber, int severity, int state,
int line, string text)
// Handles server messages
function static_handler($msgnumber, $severity, $state, $line, $text) {
return sybase_msg_handler($msgnumber, $severity, $state, $line, $text);
}
// }}}
// {{{ public bool static_handler(int msgnumber, int severity, int state, int
line, string text)
// Handles server messages
function handler($msgnumber, $severity, $state, $line, $text) {
return sybase_msg_handler($msgnumber, $severity, $state, $line, $text);
}
// }}}
}
// }}}
// {{{ void sybase_set_messagehandler_ex(string handler)
// Sets the sybase message handler and dumps the result
function sybase_set_messagehandler_ex($handler) {
var_dump(sybase_set_message_handler($handler));
}
// {{{ resource sybase_connect_ex(string charset= NULL, string appname= NULL)
// Connect to the sybase server using the defines HOST, USER and PASSWORD
function sybase_connect_ex($charset= NULL, $appname= NULL) {
sybase_min_server_severity(11); // Suppress "changed database context"
if (!($db= sybase_connect(HOST, USER, PASSWORD, $charset, $appname))) {
die('Connect to '.USER.'@'.HOST.' failed (using password: '.(PASSWORD ? 'yes' :
'no').')');
}
return $db;
}
// }}}
// {{{ void sybase_select_ex(resource dbh, string query)
// Returns all fetched rows from an SQL query
function sybase_select_ex($dbh, $query) {
printf(">>> Query: %s\n", $query);
$h= sybase_query($query, $dbh);
printf("<<< Return: %s\n", gettype($h));
flush();
if (!is_resource($h)) return $h;
$return= array();
while ($row= sybase_fetch_assoc($h)) {
$return[]= $row;
}
return $return;
}
// {{{ mixed sybase_select_single(resource dbh, string query)
// Fires an SQL query and returns the first value from the first row
function sybase_select_single($dbh, $query) {
return array_shift(sybase_fetch_row(sybase_query($query, $dbh)));
}
// }}}
?>
http://cvs.php.net/co.php/php-src/ext/sybase_ct/tests/test_connect.phpt?r=1.1&p=1
Index: php-src/ext/sybase_ct/tests/test_connect.phpt
+++ php-src/ext/sybase_ct/tests/test_connect.phpt
--TEST--
Sybase-CT connectivity
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
/* This file is part of PHP test framework for ext/sybase_ct
*
* $Id: test_connect.phpt,v 1.1 2004/01/24 02:18:13 thekid Exp $
*/
require('test.inc');
$db= sybase_connect_ex();
var_dump($db);
sybase_close($db);
?>
--EXPECTF--
resource(%d) of type (sybase-ct link)
http://cvs.php.net/co.php/php-src/ext/sybase_ct/tests/test_msghandler.phpt?r=1.1&p=1
Index: php-src/ext/sybase_ct/tests/test_msghandler.phpt
+++ php-src/ext/sybase_ct/tests/test_msghandler.phpt
--TEST--
Sybase-CT server message handler
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
/* This file is part of PHP test framework for ext/sybase_ct
*
* $Id: test_msghandler.phpt,v 1.1 2004/01/24 02:18:13 thekid Exp $
*/
require('test.inc');
$db= sybase_connect_ex();
echo 'Nonexistant: '; sybase_set_messagehandler_ex('function_does_not_exist');
echo 'Static method: '; sybase_set_messagehandler_ex(array('sybase',
'static_handler'));
echo 'Instance method: '; sybase_set_messagehandler_ex(array(new sybase(),
'handler'));
echo 'Lambda function: '; sybase_set_messagehandler_ex(create_function('', 'return
FALSE;'));
echo 'Unset: '; sybase_set_messagehandler_ex(NULL);
echo 'Function: '; sybase_set_messagehandler_ex('sybase_msg_handler');
var_dump(sybase_select_ex($db, 'select getdate(NULL)'));
sybase_close($db);
?>
--EXPECTF--
Nonexistant:
Warning: sybase_set_message_handler(): First argumented is expected to be a valid
callback, 'function_does_not_exist' was given in %s/test.inc on line %d
bool(false)
Static method: bool(true)
Instance method: bool(true)
Lambda function: bool(true)
Unset: bool(true)
Function: bool(true)
>>> Query: select getdate(NULL)
*** Caught Sybase Server Message #%d [Severity %d, state %d] at line %d
%s
<<< Return: boolean
bool(false)
http://cvs.php.net/co.php/php-src/ext/sybase_ct/tests/test_types.phpt?r=1.1&p=1
Index: php-src/ext/sybase_ct/tests/test_types.phpt
+++ php-src/ext/sybase_ct/tests/test_types.phpt
--TEST--
Sybase-CT select and types
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
/* This file is part of PHP test framework for ext/sybase_ct
*
* $Id: test_types.phpt,v 1.1 2004/01/24 02:18:13 thekid Exp $
*/
require('test.inc');
$db= sybase_connect_ex();
var_dump(sybase_select_ex($db, 'select
1 as "integer",
-2147483647 as "integer_min",
-2147483648 as "integer_min_exceed",
2147483647 as "integer_max",
2147483648 as "integer_max_exceed",
1.0 as "float",
$22.36 as "money",
"Binford" as "string",
convert(datetime, "2004-01-23") as "date",
NULL as "null",
convert(bit, 1) as "bit",
convert(smalldatetime, "2004-01-23") as "smalldate"
'));
sybase_close($db);
?>
--EXPECTF--
>>> Query: select
1 as "integer",
-2147483647 as "integer_min",
-2147483648 as "integer_min_exceed",
2147483647 as "integer_max",
2147483648 as "integer_max_exceed",
1.0 as "float",
$22.36 as "money",
"Binford" as "string",
convert(datetime, "2004-01-23") as "date",
NULL as "null",
convert(bit, 1) as "bit",
convert(smalldatetime, "2004-01-23") as "smalldate"
<<< Return: resource
array(1) {
[0]=>
array(%d) {
["integer"]=>
int(1)
["integer_min"]=>
int(-2147483647)
["integer_min_exceed"]=>
float(-2147483648)
["integer_max"]=>
int(2147483647)
["integer_max_exceed"]=>
float(2147483648)
["float"]=>
float(1)
["money"]=>
float(22.36)
["string"]=>
string(7) "Binford"
["date"]=>
string(19) "Jan 23 2004 12:00AM"
["null"]=>
NULL
["bit"]=>
int(1)
["smalldate"]=>
string(19) "Jan 23 2004 12:00AM"
}
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php