xref: /PHP-8.4/ext/odbc/tests/odbc_utils.phpt (revision 2920a266)
1--TEST--
2Test common ODBC string functionality
3--EXTENSIONS--
4odbc
5--FILE--
6<?php
7
8// 1. No, it's not quoted.
9// 2. Yes, it should be quoted because of the special character in the middle.
10$with_end_curly1 = "foo}bar";
11// 1. No, the unescaped special character in the middle breaks what would be quoted.
12// 2. Yes, it should be quoted because of the special character in the middle.
13//    Note that should_quote doesn't care about if the string is already quoted.
14//    That's why you should check if it is quoted first.
15$with_end_curly2 = "{foo}bar}";
16// 1. Yes, the special characters are escaped, so it's quoted.
17// 2. See $with_end_curly2; should_quote doesn't care about if the string is already quoted.
18$with_end_curly3 = "{foo}}bar}";
19// 1. No, it's not quoted.
20// 2. It doesn't need to be quoted because of no s
21$with_no_end_curly1 = "foobar";
22// 1. Yes, it is quoted and any characters are properly escaped.
23// 2. See $with_end_curly2.
24$with_no_end_curly2 = "{foobar}";
25
26echo "# Is quoted?\n";
27echo "With end curly brace 1: ";
28var_dump(odbc_connection_string_is_quoted($with_end_curly1));
29echo "With end curly brace 2: ";
30var_dump(odbc_connection_string_is_quoted($with_end_curly2));
31echo "With end curly brace 3: ";
32var_dump(odbc_connection_string_is_quoted($with_end_curly3));
33echo "Without end curly brace 1: ";
34var_dump(odbc_connection_string_is_quoted($with_no_end_curly1));
35echo "Without end curly brace 2: ";
36var_dump(odbc_connection_string_is_quoted($with_no_end_curly2));
37
38echo "# Should quote?\n";
39echo "With end curly brace 1: ";
40var_dump(odbc_connection_string_should_quote($with_end_curly1));
41echo "With end curly brace 2: ";
42var_dump(odbc_connection_string_should_quote($with_end_curly2));
43echo "With end curly brace 3: ";
44var_dump(odbc_connection_string_should_quote($with_end_curly3));
45echo "Without end curly brace 1: ";
46var_dump(odbc_connection_string_should_quote($with_no_end_curly1));
47echo "Without end curly brace 2: ";
48var_dump(odbc_connection_string_should_quote($with_no_end_curly2));
49
50echo "# Quote?\n";
51echo "With end curly brace 1: ";
52var_dump(odbc_connection_string_quote($with_end_curly1));
53echo "With end curly brace 2: ";
54var_dump(odbc_connection_string_quote($with_end_curly2));
55echo "With end curly brace 3: ";
56var_dump(odbc_connection_string_quote($with_end_curly3));
57echo "Without end curly brace 1: ";
58var_dump(odbc_connection_string_quote($with_no_end_curly1));
59echo "Without end curly brace 2: ";
60var_dump(odbc_connection_string_quote($with_no_end_curly2));
61
62?>
63--EXPECTF--
64# Is quoted?
65With end curly brace 1: bool(false)
66With end curly brace 2: bool(false)
67With end curly brace 3: bool(true)
68Without end curly brace 1: bool(false)
69Without end curly brace 2: bool(true)
70# Should quote?
71With end curly brace 1: bool(true)
72With end curly brace 2: bool(true)
73With end curly brace 3: bool(true)
74Without end curly brace 1: bool(false)
75Without end curly brace 2: bool(true)
76# Quote?
77With end curly brace 1: string(10) "{foo}}bar}"
78With end curly brace 2: string(13) "{{foo}}bar}}}"
79With end curly brace 3: string(15) "{{foo}}}}bar}}}"
80Without end curly brace 1: string(8) "{foobar}"
81Without end curly brace 2: string(11) "{{foobar}}}"
82