Subversion Repositories oidplus

Rev

Rev 374 | Rev 511 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 374 Rev 502
Line 27... Line 27...
27
require_once __DIR__ . '/../includes/oidplus.inc.php';
27
require_once __DIR__ . '/../includes/oidplus.inc.php';
28
 
28
 
29
$num_errs = 0;
29
$num_errs = 0;
30
$num_succ = 0;
30
$num_succ = 0;
31
 
31
 
-
 
32
if (PHP_SAPI != 'cli') echo '<pre>';
-
 
33
 
32
echo "OIDplus Database plugin testcases\n\n";
34
echo "OIDplus Database plugin testcases\n\n";
33
 
35
 
34
OIDplus::init(true, true);
36
OIDplus::init(true, true);
35
 
37
 
36
# Test MySQL
38
# Test MySQL
-
 
39
try {
37
OIDplus::baseConfig()->setValue('DATABASE_PLUGIN', 'MySQL');
40
	OIDplus::baseConfig()->setValue('DATABASE_PLUGIN', 'MySQL');
38
OIDplus::init(true, true);
41
	OIDplus::init(true, true);
39
$db = OIDplus::db();
42
	$db = OIDplus::db();
40
OIDplus::init(true, true);
43
	OIDplus::init(true, true);
41
if (function_exists('mysqli_fetch_all')) {
44
	if (function_exists('mysqli_fetch_all')) {
Line 44... Line 47...
44
	dotest($db);
47
		dotest($db);
45
	OIDplus::baseConfig()->setValue('MYSQL_FORCE_MYSQLND_SUPPLEMENT', true);
48
		OIDplus::baseConfig()->setValue('MYSQL_FORCE_MYSQLND_SUPPLEMENT', true);
46
}
49
	}
47
echo "[Without MySQLnd support] ";
50
	echo "[Without MySQLnd support] ";
48
dotest($db);
51
	dotest($db);
-
 
52
} catch (Exception $e) {
-
 
53
	echo "MySQL:\n";
-
 
54
	echo redtext($e->getMessage())."\n\n";
-
 
55
}
49
 
56
 
50
# Test PDO
57
# Test PDO
-
 
58
try {
51
OIDplus::baseConfig()->setValue('DATABASE_PLUGIN', 'PDO');
59
	OIDplus::baseConfig()->setValue('DATABASE_PLUGIN', 'PDO');
52
OIDplus::init(true, true);
60
	OIDplus::init(true, true);
53
$db = OIDplus::db();
61
	$db = OIDplus::db();
54
dotest($db);
62
	dotest($db);
-
 
63
} catch (Exception $e) {
-
 
64
	echo "PDO:\n";
-
 
65
	echo redtext($e->getMessage())."\n\n";
-
 
66
}
55
 
67
 
56
# Test ODBC
68
# Test ODBC
-
 
69
try {
57
OIDplus::baseConfig()->setValue('DATABASE_PLUGIN', 'ODBC');
70
	OIDplus::baseConfig()->setValue('DATABASE_PLUGIN', 'ODBC');
58
OIDplus::init(true, true);
71
	OIDplus::init(true, true);
59
$db = OIDplus::db();
72
	$db = OIDplus::db();
60
dotest($db);
73
	dotest($db);
-
 
74
} catch (Exception $e) {
-
 
75
	echo "ODBC:\n";
-
 
76
	echo redtext($e->getMessage())."\n\n";
-
 
77
}
61
 
78
 
62
# Test PgSQL
79
# Test PgSQL
-
 
80
try {
63
OIDplus::baseConfig()->setValue('DATABASE_PLUGIN', 'PgSQL');
81
	OIDplus::baseConfig()->setValue('DATABASE_PLUGIN', 'PgSQL');
64
OIDplus::init(true, true);
82
	OIDplus::init(true, true);
65
$db = OIDplus::db();
83
	$db = OIDplus::db();
66
dotest($db);
84
	dotest($db);
-
 
85
} catch (Exception $e) {
-
 
86
	echo "PgSQL:\n";
-
 
87
	echo redtext($e->getMessage())."\n\n";
-
 
88
}
67
 
89
 
68
# Test SQLite3
90
# Test SQLite3
-
 
91
try {
69
OIDplus::baseConfig()->setValue('DATABASE_PLUGIN', 'SQLite');
92
	OIDplus::baseConfig()->setValue('DATABASE_PLUGIN', 'SQLite');
70
OIDplus::init(true, true);
93
	OIDplus::init(true, true);
71
$db = OIDplus::db();
94
	$db = OIDplus::db();
72
dotest($db);
95
	dotest($db);
-
 
96
} catch (Exception $e) {
-
 
97
	echo "SQLite3:\n";
-
 
98
	echo redtext($e->getMessage())."\n\n";
-
 
99
}
73
 
100
 
74
# ---
101
# ---
75
 
102
 
-
 
103
if (PHP_SAPI != 'cli') {
-
 
104
	die('</pre>');
-
 
105
} else {
76
exit($num_errs > 0 ? 1 : 0);
106
	exit($num_errs > 0 ? 1 : 0);
-
 
107
}
77
 
108
 
78
# ---
109
# ---
79
 
110
 
80
function dotest($db) {
111
function dotest($db) {
81
	echo "Database: " . get_class($db) . "\n";
112
	echo "Database: " . get_class($db) . "\n";
Line 99... Line 130...
99
			echo "SQLDate (".$db->sqlDate().') '.redtext('FAILED')."\n";
130
			echo "SQLDate (".$db->sqlDate().') '.redtext('FAILED')."\n";
100
		}
131
		}
101
 
132
 
102
		// --- "Num rows" handling
133
		// --- "Num rows" handling
103
 
134
		
104
		$res = $db->query("select id from ###objects where parent = ? order by id", array('test:1'));
135
		$res = $db->query("select id from ###objects where parent = ? order by id", array('test:XXXXXXXXX'));
-
 
136
		try {
-
 
137
			$num_rows = $res->num_rows();
-
 
138
		} catch (Exception $e) {
-
 
139
			$num_rows = $e->getMessage();
-
 
140
		}
-
 
141
		echo "Num rows empty: " . ($num_rows===0 ? greentext('PASSED') : redtext('FAILED'))." ($num_rows)\n";
105
 
142
 
-
 
143
		$res = $db->query("select id from ###objects where parent = ? order by id", array('test:1'));
-
 
144
		try {
106
		$num_rows = $res->num_rows();
145
			$num_rows = $res->num_rows();
-
 
146
		} catch (Exception $e) {
-
 
147
			$num_rows = $e->getMessage();
-
 
148
		}
107
		echo "Num rows: " . ($num_rows===2 ? greentext('PASSED') : redtext('FAILED'))."\n";
149
		echo "Num rows: " . ($num_rows===2 ? greentext('PASSED') : redtext('FAILED'))." ($num_rows)\n";
108
 
150
 
109
		$res->fetch_array();
151
		$res->fetch_array();
-
 
152
		try {
110
		$num_rows = $res->num_rows();
153
			$num_rows = $res->num_rows();
-
 
154
		} catch (Exception $e) {
-
 
155
			$num_rows = $e->getMessage();
-
 
156
		}
111
		echo "Num rows after something fetched: " . ($num_rows===2 ? greentext('PASSED') : redtext('FAILED'))."\n";
157
		echo "Num rows after something fetched: " . ($num_rows===2 ? greentext('PASSED') : redtext('FAILED'))." ($num_rows)\n";
112
 
158
 
113
		$nextid = $res->fetch_array()['id'];
159
		$nextid = $res->fetch_array()['id'];
114
		echo "Num rows does not change cursor: " . ($nextid == 'test:1.2' ? greentext('PASSED') : redtext('FAILED'))."\n";
160
		echo "Num rows does not change cursor: " . ($nextid == 'test:1.2' ? greentext('PASSED') : redtext('FAILED'))."\n";
115
 
161
 
116
		$next = $res->fetch_array();
162
		$next = $res->fetch_array();
117
		echo "Fetch after EOF gives null: " . (is_null($next) ? greentext('PASSED') : redtext('FAILED'))."\n";
163
		echo "Fetch after EOF gives null: " . (is_null($next) ? greentext('PASSED') : redtext('FAILED'))."\n";
118
 
164
 
119
		// --- Simultanous prepared statements
165
		// --- Simultanous prepared statements
120
 
166
		
-
 
167
		$errmsg = '';
-
 
168
		try {
121
		$res = $db->query("select id from ###objects where parent = ? order by id", array('test:1'));
169
			$res = $db->query("select id from ###objects where parent = ? order by id", array('test:1'));
122
 
-
 
123
		$passed = false;
170
			$passed = false;
-
 
171
			//$res->num_rows(); // sponge
124
		while ($row = $res->fetch_array()) {
172
			while ($row = $res->fetch_array()) {
125
			$res2 = $db->query("select id from ###objects where parent = ? order by id", array($row['id']));
173
				$res2 = $db->query("select id from ###objects where parent = ? order by id", array($row['id']));
126
			while ($row2 = $res2->fetch_array()) {
174
				while ($row2 = $res2->fetch_array()) {
127
			}
175
				}
128
			if ($row['id'] == 'test:1.2') {
176
				if ($row['id'] == 'test:1.2') {
129
				$passed = true;
177
					$passed = true;
130
			}
178
				}
131
		}
179
			}
-
 
180
		} catch (Exception $e) {
-
 
181
			$passed = false;
-
 
182
			$errmsg = ' ('.$e->getMessage().')';
-
 
183
		}
132
		echo "Simultanous prepared statements: ".($passed ? greentext('PASSED') : redtext('FAILED'))."\n";
184
		echo "Simultanous prepared statements: ".($passed ? greentext('PASSED') : redtext('FAILED'))."$errmsg\n";
-
 
185
		
-
 
186
		if (!$passed) {
-
 
187
			// We cannot continue because the connection is in a state that cannot be recovered easily
-
 
188
			echo "Cancelled!\n\n";
-
 
189
			return;
-
 
190
		}
133
 
191
		
134
		// --- Exception handling
192
		// --- Exception handling
135
 
193
 
136
		try {
194
		try {
137
			$db->query("ABCDEF");
195
			$db->query("SELECT * from ABCDEF");
138
			echo "Exception for DirectQuery: ".redtext('FAILED').", no Exception thrown\n";
196
			echo "Exception for DirectQuery: ".redtext('FAILED').", no Exception thrown\n";
139
		} catch (Exception $e) {
197
		} catch (Exception $e) {
140
			if (strpos($e->getMessage(), 'ABCDEF') !== false) {
198
			if (strpos($e->getMessage(), 'ABCDEF') !== false) {
141
				echo "Exception for DirectQuery: ".greentext('PASSED')."\n";
199
				echo "Exception for DirectQuery: ".greentext('PASSED')."\n";
142
			} else {
200
			} else {
Line 150... Line 208...
150
		} else {
208
		} else {
151
			echo "Error-Function after failed direct query: ".redtext('FAILED').", does probably not contain DBMS error string ($msg)\n";
209
			echo "Error-Function after failed direct query: ".redtext('FAILED').", does probably not contain DBMS error string ($msg)\n";
152
		}
210
		}
153
 
211
 
154
		try {
212
		try {
155
			$db->query("FEDCBA", array(''));
213
			$db->query("SELECT * from FEDCBA", array(''));
156
			echo "Exception for PreparedQuery: ".redtext('FAILED').", no Exception thrown\n";
214
			echo "Exception for PreparedQuery: ".redtext('FAILED').", no Exception thrown\n";
157
		} catch (Exception $e) {
215
		} catch (Exception $e) {
158
			if (strpos($e->getMessage(), 'FEDCBA') !== false) {
216
			if (strpos($e->getMessage(), 'FEDCBA') !== false) {
159
				echo "Exception for PreparedQuery: ".greentext('PASSED')."\n";
217
				echo "Exception for PreparedQuery: ".greentext('PASSED')."\n";
160
			} else {
218
			} else {
Line 180... Line 238...
180
		// --- Boolean handling
238
		// --- Boolean handling
181
 
239
 
182
		$db->query("update ###objects set confidential = ? where id = 'test:1.1'", array(true));
240
		$db->query("update ###objects set confidential = ? where id = 'test:1.1'", array(true));
183
		$res = $db->query("select confidential from ###objects where id = 'test:1.1'");
241
		$res = $db->query("select confidential from ###objects where id = 'test:1.1'");
184
		$val = $res->fetch_object()->confidential;
242
		$val = $res->fetch_object()->confidential;
185
		echo "Boolean handling TRUE with prepared statement: " . ($val ? greentext('PASSED') : redtext('FAILED'))."\n";
243
		echo "Boolean handling TRUE with prepared statement (fetch): " . ($val ? greentext('PASSED') : redtext('FAILED'))."\n";
-
 
244
		$res = $db->query("select * from ###objects where id = 'test:1.1' and confidential = ?", array(true));
-
 
245
		$val = $res->fetch_object();
-
 
246
		echo "Boolean handling TRUE with prepared statement (where): " . ($val ? greentext('PASSED') : redtext('FAILED'))."\n";
186
 
247
 
187
		$db->query("update ###objects set confidential = ? where id = 'test:1.1'", array(false));
248
		$db->query("update ###objects set confidential = ? where id = 'test:1.1'", array(false));
188
		$res = $db->query("select confidential from ###objects where id = 'test:1.1'");
249
		$res = $db->query("select confidential from ###objects where id = 'test:1.1'");
189
		$val = $res->fetch_object()->confidential;
250
		$val = $res->fetch_object()->confidential;
190
		echo "Boolean handling FALSE with prepared statement: " . (!$val ? greentext('PASSED') : redtext('FAILED'))."\n";
251
		echo "Boolean handling FALSE with prepared statement (fetch): " . (!$val ? greentext('PASSED') : redtext('FAILED'))."\n";
-
 
252
		$res = $db->query("select * from ###objects where id = 'test:1.1' and confidential = ?", array(false));
-
 
253
		$val = $res->fetch_object();
-
 
254
		echo "Boolean handling FALSE with prepared statement (where): " . ($val ? greentext('PASSED') : redtext('FAILED'))."\n";
191
 
255
 
192
		$db->query("update ###objects set confidential = '1' where id = 'test:1.1'");
256
		$db->query("update ###objects set confidential = '1' where id = 'test:1.1'"); // NOTE: DO NOT USE THIS IN THE SOURCE CODE! Always use prepared statements for constant booleans
193
		$res = $db->query("select confidential from ###objects where id = 'test:1.1'");
257
		$res = $db->query("select confidential from ###objects where id = 'test:1.1'");
194
		$val = $res->fetch_object()->confidential;
258
		$val = $res->fetch_object()->confidential;
195
		echo "Boolean handling TRUE with normal statement: " . ($val ? greentext('PASSED') : redtext('FAILED'))."\n";
259
		echo "Boolean handling TRUE with normal statement (fetch): " . ($val ? greentext('PASSED') : redtext('FAILED'))."\n";
-
 
260
		$res = $db->query("select * from ###objects where id = 'test:1.1' and confidential = 1"); // NOTE: DO NOT USE THIS IN THE SOURCE CODE! Always use prepared statements for constant booleans
-
 
261
		$val = $res->fetch_object();
-
 
262
		echo "Boolean handling TRUE with normal statement (where): " . ($val ? greentext('PASSED') : redtext('FAILED'))."\n";
196
 
263
 
197
		$db->query("update ###objects set confidential = '0' where id = 'test:1.1'");
264
		$db->query("update ###objects set confidential = '0' where id = 'test:1.1'"); // NOTE: DO NOT USE THIS IN THE SOURCE CODE! Always use prepared statements for constant booleans
198
		$res = $db->query("select confidential from ###objects where id = 'test:1.1'");
265
		$res = $db->query("select confidential from ###objects where id = 'test:1.1'");
199
		$val = $res->fetch_object()->confidential;
266
		$val = $res->fetch_object()->confidential;
200
		echo "Boolean handling FALSE with normal statement: " . (!$val ? greentext('PASSED') : redtext('FAILED'))."\n";
267
		echo "Boolean handling FALSE with normal statement (fetch): " . (!$val ? greentext('PASSED') : redtext('FAILED'))."\n";
-
 
268
		$res = $db->query("select * from ###objects where id = 'test:1.1' and confidential = 0"); // NOTE: DO NOT USE THIS IN THE SOURCE CODE! Always use prepared statements for constant booleans
-
 
269
		$val = $res->fetch_object();
-
 
270
		echo "Boolean handling FALSE with normal statement (where): " . ($val ? greentext('PASSED') : redtext('FAILED'))."\n";
201
 
271
		
202
		// --- Check if transactions work
272
		// --- Check if transactions work
203
 
273
		
-
 
274
		if ($db->transaction_supported()) {
-
 
275
			echo "Transaction support: " . greentext('Supported') ."\n";
-
 
276
 
204
		$db->query("update ###objects set title = 'A' where id = 'test:1.1'");
277
			$db->query("update ###objects set title = 'A' where id = 'test:1.1'");
205
		$db->transaction_begin();
278
			$db->transaction_begin();
206
		$db->query("update ###objects set title = 'B' where id = 'test:1.1'");
279
			$db->query("update ###objects set title = 'B' where id = 'test:1.1'");
207
		$db->transaction_rollback();
280
			$db->transaction_rollback();
208
		$res = $db->query("select title from ###objects where id = 'test:1.1'");
281
			$res = $db->query("select title from ###objects where id = 'test:1.1'");
Line 214... Line 287...
214
		$db->query("update ###objects set title = 'B' where id = 'test:1.1'");
287
			$db->query("update ###objects set title = 'B' where id = 'test:1.1'");
215
		$db->transaction_commit();
288
			$db->transaction_commit();
216
		$res = $db->query("select title from ###objects where id = 'test:1.1'");
289
			$res = $db->query("select title from ###objects where id = 'test:1.1'");
217
		$val = $res->fetch_object()->title;
290
			$val = $res->fetch_object()->title;
218
		echo "Transaction commit: " . ($val == 'B' ? greentext('PASSED') : redtext('FAILED'))."\n";
291
			echo "Transaction commit: " . ($val == 'B' ? greentext('PASSED') : redtext('FAILED'))."\n";
-
 
292
		} else {
-
 
293
			echo "Transaction support: " . redtext('Not supported') ."\n";
-
 
294
		}
219
 
295
 
220
		// --- Check natOrder feature
296
		// --- Check natOrder feature
221
 
297
 
222
		$db->query("delete from ###objects where parent = 'test:1'");
298
		$db->query("delete from ###objects where parent = 'test:1'");
223
		$db->query("insert into ###objects (id, parent, title, description, confidential) values ('oid:3.1.10', 'test:1', '', '', '0')");
299
		$db->query("insert into ###objects (id, parent, title, description, confidential) values ('oid:3.1.10', 'test:1', '', '', '0')");
224
		$db->query("insert into ###objects (id, parent, title, description, confidential) values ('oid:3.1.2', 'test:1', '', '', '0')");
300
		$db->query("insert into ###objects (id, parent, title, description, confidential) values ('oid:3.1.2', 'test:1', '', '', '0')");
225
		$res = $db->query("select id from ###objects where parent = ? order by ".$db->natOrder('id'), array('test:1'));
301
		$res = $db->query("select id from ###objects where parent = ? order by ".$db->natOrder('id'), array('test:1'));
-
 
302
		//$res->num_rows(); // sponge
226
		$val = $res->fetch_object()->id;
303
		$val = $res->fetch_object()->id;
227
		echo "Natural OID Sorting (< 16 Bit): " . ($val == 'oid:3.1.2' ? greentext('PASSED') : redtext('FAILED'))."\n";
304
		echo "Natural OID Sorting (< 16 Bit): " . ($val == 'oid:3.1.2' ? greentext('PASSED') : redtext('FAILED'))."\n";
228
 
305
 
229
		$db->query("delete from ###objects where parent = 'test:1'");
306
		$db->query("delete from ###objects where parent = 'test:1'");
230
		$db->query("insert into ###objects (id, parent, title, description, confidential) values ('oid:2.25.317919736312109525688528068157180855579', 'test:1', '', '', '0')");
307
		$db->query("insert into ###objects (id, parent, title, description, confidential) values ('oid:2.25.317919736312109525688528068157180855579', 'test:1', '', '', '0')");
231
		$db->query("insert into ###objects (id, parent, title, description, confidential) values ('oid:2.25.67919736312109525688528068157180855579', 'test:1', '', '', '0')");
308
		$db->query("insert into ###objects (id, parent, title, description, confidential) values ('oid:2.25.67919736312109525688528068157180855579', 'test:1', '', '', '0')");
232
		$res = $db->query("select id from ###objects where parent = ? order by ".$db->natOrder('id'), array('test:1'));
309
		$res = $db->query("select id from ###objects where parent = ? order by ".$db->natOrder('id'), array('test:1'));
-
 
310
		//$res->num_rows(); // sponge
233
		$val = $res->fetch_object()->id;
311
		$val = $res->fetch_object()->id;
234
		echo "Natural OID Sorting (128 Bit): " . ($val == 'oid:2.25.67919736312109525688528068157180855579' ? greentext('PASSED') : redtext('FAILED'))."\n";
312
		echo "Natural OID Sorting (128 Bit): " . ($val == 'oid:2.25.67919736312109525688528068157180855579' ? greentext('PASSED') : redtext('FAILED'))."\n";
235
 
313
 
236
		$db->query("delete from ###objects where parent = 'test:1'");
314
		$db->query("delete from ###objects where parent = 'test:1'");
237
		$db->query("insert into ###objects (id, parent, title, description, confidential) values ('abc:3.1.10', 'test:1', '', '', '0')");
315
		$db->query("insert into ###objects (id, parent, title, description, confidential) values ('abc:3.1.10', 'test:1', '', '', '0')");
238
		$db->query("insert into ###objects (id, parent, title, description, confidential) values ('abc:3.1.2', 'test:1', '', '', '0')");
316
		$db->query("insert into ###objects (id, parent, title, description, confidential) values ('abc:3.1.2', 'test:1', '', '', '0')");
239
		$res = $db->query("select id from ###objects where parent = ? order by ".$db->natOrder('id'), array('test:1'));
317
		$res = $db->query("select id from ###objects where parent = ? order by ".$db->natOrder('id'), array('test:1'));
-
 
318
		//$res->num_rows(); // sponge
240
		$val = $res->fetch_object()->id;
319
		$val = $res->fetch_object()->id;
241
		echo "Non-Natural Sorting for Non-OIDs: " . ($val == 'abc:3.1.10' ? greentext('PASSED') : redtext('FAILED'))."\n";
320
		echo "Non-Natural Sorting for Non-OIDs: " . ($val == 'abc:3.1.10' ? greentext('PASSED') : redtext('FAILED'))."\n";
242
 
321
 
243
		// --- Test insert_id()
322
		// --- Test insert_id()
244
 
323
 
245
		$db->query("delete from ###log_object where object = 'test:1'");
324
		$db->query("delete from ###log_object where object = 'test:1'");
246
		$cur = $db->insert_id();
325
		$cur = $db->insert_id();
247
		echo "Insert ID on non-insert: " . ($cur == 0 ? greentext('PASSED') : redtext('FAILED'))." ($cur)\n";
326
		echo "Insert ID on non-insert: " . ($cur == 0 ? greentext('PASSED') : redtext('FAILED'))." ($cur)\n";
248
		$db->query("insert into ###log_object (log_id, object) values (1000, 'test:1')");
327
		$db->query("insert into ###log_object (log_id, severity, object) values (1000, 0, 'test:1')");
249
		$prev = $db->insert_id();
328
		$prev = $db->insert_id();
250
		$db->query("insert into ###log_object (log_id, object) values (2000, 'test:1')");
329
		$db->query("insert into ###log_object (log_id, severity, object) values (2000, 1, 'test:1')");
251
		$cur = $db->insert_id();
330
		$cur = $db->insert_id();
252
		echo "Insert ID on actual inserts: " . ($cur == $prev+1 ? greentext('PASSED') : redtext('FAILED'))." ($prev => $cur)\n";
331
		echo "Insert ID on actual inserts: " . ($cur == $prev+1 ? greentext('PASSED') : redtext('FAILED'))." ($prev => $cur)\n";
253
		if ($cur != $prev+1);
332
		if ($cur != $prev+1);
254
		$db->query("delete from ###log_object where object = 'test:1'");
333
		$db->query("delete from ###log_object where object = 'test:1'");
255
		$cur = $db->insert_id();
334
		$cur = $db->insert_id();
256
		echo "Non-Insert query will reset insert ID: " . ($cur == 0 ? greentext('PASSED') : redtext('FAILED'))." ($cur)\n";
335
		echo "Non-Insert query will reset insert ID: " . ($cur == 0 ? greentext('PASSED') : redtext('FAILED'))." ($cur)\n";
257
 
336
 
258
	} finally {
337
	} finally {
-
 
338
		try {
259
		$db->query("delete from ###objects where parent = 'test:1'");
339
			$db->query("delete from ###objects where parent = 'test:1'");
-
 
340
		}catch(Exception $e) {}
260
	}
341
	}
261
	$db->disconnect();
342
	$db->disconnect();
262
	echo "\n";
343
	echo "\n";
263
}
344
}
264
 
345
 
265
function redtext($str) {
346
function redtext($str) {
266
	global $num_errs;
347
	global $num_errs;
267
	$num_errs++;
348
	$num_errs++;
268
	return "\033[31m$str\033[0m";
349
	return PHP_SAPI == 'cli' ? "\033[31m$str\033[0m" : '<font color="red">'.$str.'</font>';
269
}
350
}
270
 
351
 
271
function greentext($str) {
352
function greentext($str) {
272
	global $num_succ;
353
	global $num_succ;
273
	$num_succ++;
354
	$num_succ++;
274
	return "\033[32m$str\033[0m";
355
	return PHP_SAPI == 'cli' ? "\033[32m$str\033[0m" : '<font color="green">'.$str.'</font>';
275
}
356
}