~pbms-core/pbms/5.11-beta

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
--TEST--
Buffered based insert BLOB data
--SKIPIF--
<?php if (!extension_loaded("PBMS")) print "skip"; ?>
--POST--
--GET--
--FILE--
<?php 
	// Functions tested:
	// pbms_connect() 
	// pbms_put_data()
	// pbms_get_data()
	// pbms_close()

	include "pbms_utils.php";

	// Connecting, selecting database
	pbms_connect($host, $port, $database)
		or pbms_error_and_die("Could not connect");
		
	$mysql = mysql_connect()
		or mysql_error_and_die("Could not connect");

	print "Connected successfully\n";
	init_php_test_database($mysql, $engine, $database);
	
	mysql_query("Use $database;")
	or mysql_error_and_die("List databases failed");
	
	mysql_query("Delete from test1; ")
		or mysql_error_and_die("Query Failed: $query");

	// Create a few BLOBs
	$blob_data[0] = "A BLOB";
	$blob_data[1] = "This is a some what larger BLOB, but still very tiny by BLOB standards.";
	$blob_data[2] = build_a_blob(1024);
	$blob_data[3] = build_a_blob(10 *1024);
	
	$cnt = 1;
	foreach ($blob_data as $val) {
	
		// For this test I will ommit the table name.
		$blob_ref = pbms_put_data($val)
			or pbms_error_and_die("pbms_put_data() error");

		$query = sprintf ("Insert into test1(c1, c2) values( %d, '%s');", $cnt, $blob_ref) ;
		//printf("%s\n", $query);
		mysql_query($query)
			or mysql_error_and_die("Query Failed: $query");
			
		$cnt++;
	}

	$result = mysql_query("select c1, c2 from test1 order by c1; ")
		or mysql_error_and_die("Query Failed: $query");

	$cnt = 0;
	while ($row = mysql_fetch_assoc($result)) {
		//printf("row(%d): %d, %s\n",  $cnt, $row['c1'], $row['c2']);

		$output = pbms_get_data($row['c2'])
			or pbms_error_and_die("pbms_get_data() error ");

		if (strcmp($output, $blob_data[$cnt])) {
			printf("Data mismatch in row %d lengths: %d, %d\n", $cnt, strlen($blob_data[$cnt]), strlen($output));
			//printf("Original: -->%s<--\n", $blob_data[$cnt]);
			//printf("Returned: -->%s<--\n", $output);
		}
		

		$cnt++;
	}
	
	print "Buffered insert BLOB data done.\n";
		
	// Free resultset
	mysql_free_result($result);

	// Closing connection
	pbms_close();
	mysql_close($mysql);
?>
--EXPECT--
Connected successfully
Buffered insert BLOB data done.