~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
87
88
89
90
91
92
93
94
95
96
97
98
99
--TEST--
Stream based insert BLOB data with md5 digest
--SKIPIF--
<?php if (!extension_loaded("PBMS")) print "skip"; ?>
--POST--
--GET--
--FILE--
<?php 
	// Functions tested:
	// pbms_connect() 
	// pbms_read_stream()
	// pbms_write_stream()
	// pbms_get_md5_digest()
	// pbms_close()

	include "pbms_utils.php";

	pbms_connect($host, $port, $database)
		or pbms_error_and_die("Could not connect\n");
		
	$mysql = mysql_connect()
		or mysql_error_and_die("Could not connect\n");

	print "Connected successfully\n";
	init_php_test_database($mysql, $engine, $database);
	
	mysql_query("Use $database;")
	or mysql_error_and_die("Use $database  failed\n");
	
	if (mysql_query("Delete from test1; ") == FALSE) {
		mysql_error_and_die("Delete from test1 Failed: \n");
	}

	// Create a few BLOBs
	$blob_file[0] = create_a_blob(1, "A BLOB");
	$blob_file[1] = create_a_blob(2, "This is a some what larger BLOB, but still very tiny by BLOB standards.");
	$blob_file[2] = create_a_blob(3, build_a_blob(1024));
	$blob_file[3] = create_a_blob(4, build_a_blob(10 *1024));
	$blob_file[4] = create_a_big_blob(5, 1024 * 1024);
	
	$cnt = 1;
	foreach ($blob_file as $val) {
	
		$fh = fopen($val, "r")
			or die("fopen() error\n");
		
		// Stream the file data to the PBMS daemon.
		$blob_ref = pbms_read_stream($fh, filesize($val), "test1", md5_file($val, true))
			or pbms_error_and_die("pbms_read_stream($val) error\n");

		fclose($fh);

		$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");
			
		$blob_refs[$cnt] = $blob_ref;	
		$cnt++;
	}

	$cnt = 1;
	foreach ($blob_file as $val) {
		// Test stream access:
		$fh = fopen("phptest.blob", "w+")
			or die("fopen() error");
		
		// Get the BLOB back	
		pbms_write_stream($fh, $blob_refs[$cnt])
			or pbms_error_and_die("pbms_write_stream($val) error");
		
		$pbms_checksum = pbms_get_md5_digest();
		$php_checksum = md5_file($val, true);
		
		if (strcmp($pbms_checksum, $php_checksum)) {
			printf("Checksum error for %s : %s != %s\n", $val, bin2hex($pbms_checksum), bin2hex($php_checksum));
			die("Checksum test failed between phptest.blob and $val\n");
		}
		
		fclose($fh);
		
		compare_blob_files("phptest.blob", $val);
		unlink("phptest.blob");
		$cnt++;
	}
	
	foreach ($blob_file as $val) 
		unlink($val);
		
	print "Stream insert BLOB data using md5 digest done.\n";
		
	// Closing connection
	pbms_close();
	mysql_close($mysql);
?>
--EXPECT--
Connected successfully
Stream insert BLOB data using md5 digest done.