1--TEST--
2Sybase-CT server message handler
3--SKIPIF--
4<?php require('skipif.inc'); ?>
5--FILE--
6<?php
7/* This file is part of PHP test framework for ext/sybase_ct
8 *
9 * $Id$
10 */
11
12  require('test.inc');
13
14  // {{{ bool sybase_msg_handler(int msgnumber, int severity, int state, int line, string text)
15  //     Handles server messages
16  function user_message_handler($msgnumber, $severity, $state, $line, $text) {
17    switch ($msgnumber) {
18      case 0:       // print message
19        printf("!!! %s\n", trim($text));
20        return;
21
22      case 174:     // The function 'GETDATE' requires 0 arguments.
23      case 11021:   // Function GETDATE invoked with wrong number or type of argument(s)
24        printf("*** Caught '%s'\n", trim($text));
25        return;
26    }
27    printf("Cannot handle message #%d\n", $msgnumber);
28    return FALSE;   // Indicate we can't handle this
29  }
30  // }}}
31
32  sybase_set_messagehandler_ex('user_message_handler');
33  $db= sybase_connect_ex();
34  sybase_min_server_severity(0);
35
36  // These are handled
37  var_dump(sybase_select_ex($db, 'select getdate(NULL)'));
38  var_dump(sybase_select_ex($db, 'print "Hi"'));
39
40  // These aren't
41  var_dump(sybase_select_ex($db, 'use NULL'));
42  var_dump(sybase_select_ex($db, 'select convert(datetime, "notadate")'));
43
44  sybase_close($db);
45?>
46--EXPECTF--
47bool(true)
48>>> Query: select getdate(NULL)
49*** Caught '%s'
50<<< Return: boolean
51bool(false)
52>>> Query: print "Hi"
53!!! Hi
54<<< Return: boolean
55bool(true)
56>>> Query: use NULL
57Cannot handle message #156
58
59Warning: sybase_query(): Sybase:  Server message:  Incorrect syntax near the keyword 'NULL'.
60 (severity 15, procedure N/A) in %s on line %d
61<<< Return: boolean
62bool(false)
63>>> Query: select convert(datetime, "notadate")
64Cannot handle message #249
65
66Warning: sybase_query(): Sybase:  Server message:  Syntax error during explicit conversion of VARCHAR value 'notadate' to a DATETIME field.
67 (severity 16, procedure N/A) in %s on line %d
68<<< Return: boolean
69bool(false)
70