1--TEST-- 2InterBase: misc sql types (may take a while) 3--SKIPIF-- 4<?php include("skipif.inc"); ?> 5--FILE-- 6<?php /* $Id$ */ 7 8 require("interbase.inc"); 9 ibase_connect($test_base); 10 11 ibase_query( 12 "create table test3 ( 13 iter integer not null, 14 v_char char(1000), 15 v_date timestamp, 16 v_decimal4_2 decimal(4,2), 17 v_decimal4_0 decimal(4,0), 18 v_decimal7_2 decimal(7,2), 19 v_decimal7_0 decimal(7,0), 20 v_numeric15_15 numeric(15,15), 21 v_numeric15_0 numeric(15,0), 22 v_double double precision, 23 v_float float, 24 v_integer integer, 25 v_smallint smallint, 26 v_varchar varchar(10000) 27 )"); 28 ibase_commit(); 29 30 /* should fail, but gracefully */ 31 @ibase_query("insert into test3 (iter) values (?)", null); 32 33 /* if timefmt is not supported, suppress error here */ 34 ini_set('ibase.timestampformat',"%m/%d/%Y %H:%M:%S"); 35 36 for($iter = 0; $iter < 10; $iter++){ 37 /* prepare data */ 38 $v_char = rand_str(1000); 39 $v_date = rand_datetime(); 40 $v_decimal4_2 = rand_number(4,2); 41 $v_decimal4_0 = rand_number(4,0); 42 $v_decimal7_2 = rand_number(7,2); 43 $v_decimal7_0 = rand_number(7,0); 44 $v_numeric15_15 = rand_number(15,15); 45 $v_numeric15_0 = $iter ? rand_number(15,0) : 0; 46 $v_double = rand_number(18); 47 $v_float = rand_number(7); 48 $v_integer = rand_number(9,0); 49 $v_smallint = rand_number(5) % 32767; 50 $v_varchar = rand_str(10000); 51 52 ibase_query( 53 "insert into test3 (iter, v_char,v_date,v_decimal4_2, v_decimal4_0, v_decimal7_2, v_decimal7_0,v_numeric15_15, v_numeric15_0,v_double,v_float,v_integer,v_smallint,v_varchar) 54 values ($iter, '$v_char','$v_date',$v_decimal4_2, $v_decimal4_0, $v_decimal7_2, $v_decimal7_0,$v_numeric15_15, $v_numeric15_0,$v_double,$v_float,$v_integer,$v_smallint,'$v_varchar')"); 55 $sel = ibase_query("select * from test3 where iter = $iter"); 56 $row = ibase_fetch_object($sel); 57 if(substr($row->V_CHAR,0,strlen($v_char)) != $v_char){ 58 echo " CHAR fail:\n"; 59 echo " in: $v_char\n"; 60 echo " out: $row->V_CHAR\n"; 61 } 62 if($row->V_DATE != $v_date){ 63 echo " DATE fail\n"; 64 echo " in: $v_date\n"; 65 echo " out: $row->V_DATE\n"; 66 } 67 if($row->V_DECIMAL4_2 != $v_decimal4_2){ 68 echo " DECIMAL4_2 fail\n"; 69 echo " in: $v_decimal4_2\n"; 70 echo " out: $row->V_DECIMAL4_2\n"; 71 } 72 if($row->V_DECIMAL4_0 != $v_decimal4_0){ 73 echo " DECIMAL4_0 fail\n"; 74 echo " in: $v_decimal4_0\n"; 75 echo " out: $row->V_DECIMAL4_0\n"; 76 } 77 if($row->V_DECIMAL7_2 != $v_decimal7_2){ 78 echo " DECIMAL7_2 fail\n"; 79 echo " in: $v_decimal7_2\n"; 80 echo " out: $row->V_DECIMAL7_2\n"; 81 } 82 if($row->V_DECIMAL7_0 != $v_decimal7_0){ 83 echo " DECIMAL7_0 fail\n"; 84 echo " in: $v_decimal7_0\n"; 85 echo " out: $row->V_DECIMAL7_0\n"; 86 } 87 if($row->V_NUMERIC15_15 != $v_numeric15_15){ 88 echo " NUMERIC15_15 fail\n"; 89 echo " in: $v_numeric15_15\n"; 90 echo " out: $row->V_NUMERIC15_15\n"; 91 } 92 if($row->V_NUMERIC15_0 != (string)$v_numeric15_0){ 93 echo " NUMERIC15_0 fail\n"; 94 echo " in: $v_numeric15_0\n"; 95 echo " out: $row->V_NUMERIC15_0\n"; 96 } 97 98 if(abs($row->V_DOUBLE - $v_double) > abs($v_double / 1E15)){ 99 echo " DOUBLE fail\n"; 100 echo " in: $v_double\n"; 101 echo " out: $row->V_DOUBLE\n"; 102 } 103 if(abs($row->V_FLOAT - $v_float) > abs($v_float / 1E7)){ 104 echo " FLOAT fail\n"; 105 echo " in: $v_float\n"; 106 echo " out: $row->V_FLOAT\n"; 107 } 108 if($row->V_INTEGER != $v_integer){ 109 echo " INTEGER fail\n"; 110 echo " in: $v_integer\n"; 111 echo " out: $row->V_INTEGER\n"; 112 } 113 if($row->V_SMALLINT != $v_smallint){ 114 echo " SMALLINT fail\n"; 115 echo " in: $v_smallint\n"; 116 echo " out: $row->V_SMALLINT\n"; 117 } 118 119 if(substr($row->V_VARCHAR,0,strlen($v_varchar)) != $v_varchar){ 120 echo " VARCHAR fail:\n"; 121 echo " in: $v_varchar\n"; 122 echo " out: $row->V_VARCHAR\n"; 123 } 124 125 ibase_free_result($sel); 126 } /* for($iter) */ 127 128 /* check for correct handling of duplicate field names */ 129 $q = ibase_query('SELECT 1 AS id, 2 AS id, 3 AS id, 4 AS id, 5 AS id, 6 AS id, 7 AS id, 8 AS id, 9 AS id, 130 10 AS id, 11 AS id, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 FROM rdb$database'); 131 var_dump(ibase_fetch_assoc($q)); 132 133 ibase_close(); 134 echo "end of test\n"; 135?> 136--EXPECT-- 137array(22) { 138 ["ID"]=> 139 int(1) 140 ["ID_01"]=> 141 int(2) 142 ["ID_02"]=> 143 int(3) 144 ["ID_03"]=> 145 int(4) 146 ["ID_04"]=> 147 int(5) 148 ["ID_05"]=> 149 int(6) 150 ["ID_06"]=> 151 int(7) 152 ["ID_07"]=> 153 int(8) 154 ["ID_08"]=> 155 int(9) 156 ["ID_09"]=> 157 int(10) 158 ["ID_10"]=> 159 int(11) 160 ["CONSTANT"]=> 161 int(12) 162 ["CONSTANT_01"]=> 163 int(13) 164 ["CONSTANT_02"]=> 165 int(14) 166 ["CONSTANT_03"]=> 167 int(15) 168 ["CONSTANT_04"]=> 169 int(16) 170 ["CONSTANT_05"]=> 171 int(17) 172 ["CONSTANT_06"]=> 173 int(18) 174 ["CONSTANT_07"]=> 175 int(19) 176 ["CONSTANT_08"]=> 177 int(20) 178 ["CONSTANT_09"]=> 179 int(21) 180 ["CONSTANT_10"]=> 181 int(22) 182} 183end of test 184