~barry-leslie/pbmsphp/Version2

« back to all changes in this revision

Viewing changes to tests/pbms_utils.php

  • Committer: Barry.Leslie at PrimeBase
  • Date: 2011-05-20 17:39:15 UTC
  • Revision ID: barry.leslie@primebase.com-20110520173915-7k05woc98k6ma9pw
PBMS version 2 php module

Show diffs side-by-side

added added

removed removed

Lines of Context:
373
373
        //------------------------------------------------------
374
374
        function dump_pbms_reference($mysql)
375
375
        {
 
376
                //$query = "select * from pbms_reference;" ;
376
377
                $query = "select Table_name, Blob_id,  Blob_url from pbms_reference;" ;
377
378
                $result = mysql_query($query, $mysql)
378
379
                        or mysql_error_and_die("Query Failed: $query");
379
380
                
380
 
                $row = mysql_fetch_assoc($result)
381
 
                        or mysql_error_and_die("No row was returned: $query");
 
381
//printf("mysql_num_rows(): %d\n", mysql_num_rows($result));
 
382
                //$row = mysql_fetch_assoc($result)
 
383
                //      or mysql_error_and_die("No row was returned: $query");
382
384
                
383
385
                print "\n=========================================\n";
384
386
                while ($row = mysql_fetch_assoc($result)) {
410
412
                $ref = $row[1];
411
413
                
412
414
                mysql_free_result($result);
413
 
                
414
415
        //dump_pbms_reference($mysql);
415
 
                $query = sprintf ("select Blob_id from pbms_reference where Blob_url = '%s';", $ref) ;
 
416
                $query = sprintf ("select Blob_id from pbms_reference where Blob_url = '%s';", rtrim($ref, "\0")) ;
416
417
                $result = mysql_query($query, $mysql)
417
 
                        or mysql_error_and_die("Query Failed: $query\n");
 
418
                        or mysql_error_and_die("Query Failed: \n$query\n");
418
419
 
419
420
                if (mysql_num_rows($result) != 1)
420
421
                        die("Unexpected number of rows: $query\n");
430
431
        //------------------------------------------------------
431
432
        function getReferencedBlobCount($mysql, $table)
432
433
        {
433
 
                $query = sprintf ("select count(*) from pbms_reference where Table_name = '%s' and Deletion_time IS NULL;", $table) ;
 
434
                $query = sprintf ("select count(*) from pbms_reference where Table_name = '%s';", $table) ;
434
435
                $result = mysql_query($query, $mysql)
435
436
                        or mysql_error_and_die("Query Failed: $query");
436
437
                        
437
438
                $row = mysql_fetch_row($result);
438
439
                mysql_free_result($result);
439
 
                
440
440
                return $row[0];
441
441
        }
442
442
        
443
443
        //------------------------------------------------------
444
 
        function testBlobStatus($mysql, $id, $table, $expect_null)
 
444
        function testBlobStatus($mysql, $id, $table, $expect_row)
445
445
        {
446
446
                //print "testBlobStatus(mysql, $id, $table, $expect_null)\n";
447
447
                
448
 
                $try_again = TRUE;
449
 
                while (TRUE) {
450
 
                        $query = sprintf ("select Blob_url, Deletion_time from pbms_reference where Table_name = '%s' and Blob_id = %d;", $table, $id) ;
451
 
                        $result = mysql_query($query, $mysql)
452
 
                                or mysql_error_and_die("Query Failed: $query");
453
 
 
454
 
                        if (mysql_num_rows($result) != 1)
455
 
                                die("Unexpected number of rows: $query\n");
456
 
                                
457
 
                        $row = mysql_fetch_assoc($result);
458
 
                        mysql_free_result($result);
459
 
                                
460
 
                        if (($expect_null == TRUE) and ($row['Deletion_time'] != NULL))
461
 
                                $msg = "Null Deletion_time expected but non NULL returned: \n$query\n";
462
 
                        elseif (($expect_null == FALSE) and ($row['Deletion_time'] == NULL))
463
 
                                $msg = "An unexpects NULL Deletion_time returned: \n$query\n";
464
 
                        else
465
 
                                return;
 
448
                $query = sprintf ("select Blob_url from pbms_reference where Table_name = '%s' and Blob_id = %d;", $table, $id) ;
 
449
                $result = mysql_query($query, $mysql)
 
450
                        or mysql_error_and_die("Query Failed: $query");
466
451
                        
467
 
                        if ($try_again)
468
 
                                sleep(2); // Give the PBMS transaction manager some time to process the transactions.
469
 
                        else
470
 
                                die($msg);
471
 
                                
472
 
                        $try_again = FALSE;
 
452
                $cnt = mysql_num_rows($result);
 
453
                mysql_free_result($result);                     
 
454
 
 
455
                if ($cnt == 0) {
 
456
                        if ($expect_row == TRUE)
 
457
                                die("No row was returned:\n$query\n");
 
458
                } else {
 
459
                        if ($expect_row == FALSE)
 
460
                                die("An unexpected row was returned:\n$query\n");
473
461
                }
474
462
                
 
463
 
475
464
        }
476
465
        
477
466