Annotation of embedaddon/php/ext/interbase/tests/interbase.inc, revision 1.1

1.1     ! misho       1: <?php /* $Id: interbase.inc 267053 2008-10-07 12:51:21Z felipe $ */
        !             2: 
        !             3: srand((double)microtime()*1000000);
        !             4: 
        !             5: $user = 'SYSDBA';
        !             6: $password = 'masterkey';
        !             7: ini_set('ibase.default_user',$user);
        !             8: ini_set('ibase.default_password',$password);
        !             9: 
        !            10: /* we need just the generated name, not the file itself */
        !            11: unlink($test_base = tempnam('/tmp',"php_ibase_test"));
        !            12: 
        !            13: function init_db()
        !            14: {
        !            15:        global $test_base, $user, $password;
        !            16: 
        !            17:        $test_db = ibase_query(IBASE_CREATE, 
        !            18:                sprintf("CREATE SCHEMA '%s' USER '%s' PASSWORD '%s' DEFAULT CHARACTER SET %s",$test_base,
        !            19:                $user, $password, ($charset = ini_get('ibase.default_charset')) ? $charset : 'NONE'));
        !            20:        $tr = ibase_trans($test_db);
        !            21:        ibase_query($tr,"create table test1 (i integer, c varchar(100))");
        !            22:        ibase_commit_ret($tr);
        !            23:        ibase_query($tr,"insert into test1(i, c) values(1, 'test table not created with isql')");
        !            24:        ibase_commit($tr);
        !            25:        ibase_close($test_db);
        !            26: }
        !            27: 
        !            28: function cleanup_db()
        !            29: {
        !            30:        global $test_base;
        !            31:     
        !            32:        $r = ibase_connect($test_base);
        !            33:        ibase_drop_db($r);
        !            34: }
        !            35: 
        !            36: register_shutdown_function('cleanup_db');
        !            37: init_db();
        !            38: 
        !            39: function out_table($table_name)
        !            40: {
        !            41:        echo "--- $table_name ---\n";
        !            42:        $res = ibase_query("select * from $table_name");
        !            43:        while ($r = ibase_fetch_row($res)) {
        !            44:                echo join("\t",$r)."\t\n";
        !            45:        }
        !            46:        ibase_free_result($res);
        !            47:        echo "---\n";
        !            48: }
        !            49: 
        !            50: function out_result($result, $table_name = "")
        !            51: {
        !            52:        echo "--- $table_name ---\n";
        !            53:        while ($r = ibase_fetch_row($result)) {
        !            54:                echo join("\t",$r)."\t\n";
        !            55:        }
        !            56:        echo "---\n";
        !            57: }
        !            58: 
        !            59: function out_result_trap_error($result, $table_name = "")
        !            60: {
        !            61:    echo "--- $table_name ---\n";
        !            62:    while ($r = @ibase_fetch_row($result)) {
        !            63:                echo join("\t",$r)."\t\n";
        !            64:    }
        !            65:    echo "errmsg [" . ibase_errmsg() . "]\t\n";
        !            66:    echo "---\n";
        !            67: }
        !            68: 
        !            69: /* M/D/Y H:M:S */
        !            70: function rand_datetime()
        !            71: {
        !            72:     return sprintf("%02d/%02d/%4d %02d:%02d:%02d",
        !            73:                rand()%12+1, rand()%28+1, rand()%100+1910,
        !            74:                rand()%24,   rand()%60,  rand()%60);
        !            75: }
        !            76: 
        !            77: /* random binary string  */
        !            78: function rand_binstr($max_len)
        !            79: {
        !            80:     $len = rand() % $max_len;
        !            81:     $s = "";
        !            82:     while($len--) {
        !            83:         $s .= sprintf("%c", rand() % 256);
        !            84:     }
        !            85:     return $s;
        !            86: }
        !            87: 
        !            88: function rand_str($max_len)
        !            89: {
        !            90:     $len = rand() % $max_len;
        !            91:     $s = "";
        !            92:     while ($len--) {
        !            93:         $s .= sprintf("%c", rand() % 26 + 65);
        !            94:     }
        !            95:     return $s;
        !            96: }
        !            97: 
        !            98: function rand_number($len , $prec = -1, $sign = 1)
        !            99: {
        !           100:     if ($prec == -1) {
        !           101:         $n = substr(rand() . rand(), 0, rand() % $len + 1);
        !           102:         if (strlen($n) < $len) {
        !           103:                $n .= "." . substr(rand(), 0, rand() % ($len - strlen($n)) + 1);
        !           104:         }
        !           105:     } else if ($prec == 0) {
        !           106:         $n = substr(rand() . rand(), 0, rand() % $len + 1);
        !           107:     } else if (($prec - $len) == 0) {
        !           108:         $n = substr(rand() . rand(), 0, 1);
        !           109:         $n .= "." . substr(rand(), 0, $prec);
        !           110:     } else {
        !           111:         $n = substr(rand() . rand(), 0, rand() % ($len - $prec) + 1);
        !           112:         $n .= "." . substr(rand(), 0, $prec);
        !           113:     }
        !           114:     if ($sign && (rand() % 3 == 0)) {
        !           115:         $n = "-" .$n;
        !           116:     }
        !           117:     return $n;
        !           118: }
        !           119: 
        !           120: ?>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>