mirror of
https://github.com/php/php-src.git
synced 2024-09-22 18:37:25 +00:00
Changes :
. Add the distinction between NUMBER and FLOAT types . Changing BFLOAT text to be BINARY_FLOAT . Changing BDOUBLE text to be BINARY_DOUBLE . Add the data types names for NCHAR, NVARCHAR and NCLOB . Few changes in the tests Also, my commit is correcting a bug in the function oci_stmt_describe. PDO override the values given for the precision using the content of the pdo_column_data property 'precision'. That value was set in oci_stmt_describe but with the value of OCI_ATTR_SCALE, causing a bug for the precision value returned by getColumnMeta() (values between 12800 and 14000 probably due to the conversion of a sb1 to a zend_ulong)
This commit is contained in:
parent
d25d9276ff
commit
5dedf15d2d
@ -553,7 +553,7 @@ static int oci_stmt_describe(pdo_stmt_t *stmt, int colno) /* {{{ */
|
||||
STMT_CALL_MSG(OCIAttrGet, "OCI_ATTR_NAME",
|
||||
(param, OCI_DTYPE_PARAM, &colname, &namelen, OCI_ATTR_NAME, S->err));
|
||||
|
||||
col->precision = scale;
|
||||
col->precision = precis;
|
||||
col->maxlen = data_size;
|
||||
col->name = zend_string_init((char *)colname, namelen, 0);
|
||||
|
||||
@ -598,7 +598,7 @@ static int oci_stmt_describe(pdo_stmt_t *stmt, int colno) /* {{{ */
|
||||
S->cols[colno].datalen = 1024;
|
||||
#endif
|
||||
} else if (dtype == SQLT_BIN) {
|
||||
S->cols[colno].datalen = (ub4) col->maxlen * 2; // raw characters to hex digits
|
||||
S->cols[colno].datalen = (ub4) col->maxlen * 2; /* raw characters to hex digits */
|
||||
} else {
|
||||
S->cols[colno].datalen = (ub4) (col->maxlen * S->H->max_char_width);
|
||||
}
|
||||
@ -797,16 +797,17 @@ static int oci_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, size_t *len
|
||||
static int oci_stmt_col_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_value) /* {{{ */
|
||||
{
|
||||
pdo_oci_stmt *S = (pdo_oci_stmt*)stmt->driver_data;
|
||||
pdo_oci_column *C = &S->cols[colno];
|
||||
|
||||
pdo_oci_column *C;
|
||||
OCIParam *param = NULL;
|
||||
OraText *colname;
|
||||
OraText * schema;
|
||||
ub2 dtype, data_size, precis = 0;
|
||||
ub2 dtype, data_size;
|
||||
ub2 precis = 0;
|
||||
ub4 namelen, schemalen, typelen, objlen;
|
||||
sb1 scale;
|
||||
char *str;
|
||||
zval flags;
|
||||
ub1 isnull;
|
||||
ub1 isnull, charset_form;
|
||||
if (!S->stmt) {
|
||||
return FAILURE;
|
||||
}
|
||||
@ -815,6 +816,8 @@ static int oci_stmt_col_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_val
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
C = &S->cols[colno];
|
||||
|
||||
array_init(return_value);
|
||||
array_init(&flags);
|
||||
|
||||
@ -832,9 +835,19 @@ static int oci_stmt_col_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_val
|
||||
STMT_CALL_MSG(OCIAttrGet, "OCI_ATTR_PRECISION",
|
||||
(param, OCI_DTYPE_PARAM, &precis, 0, OCI_ATTR_PRECISION, S->err));
|
||||
|
||||
/* column scale */
|
||||
STMT_CALL_MSG(OCIAttrGet, "OCI_ATTR_SCALE",
|
||||
(param, OCI_DTYPE_PARAM, &scale, 0, OCI_ATTR_SCALE, S->err));
|
||||
|
||||
/* string column charset form */
|
||||
if(dtype == SQLT_CHR || dtype == SQLT_VCS || dtype == SQLT_AFC || dtype == SQLT_CLOB){
|
||||
STMT_CALL_MSG(OCIAttrGet, "OCI_ATTR_CHARSET_FORM",
|
||||
(param, OCI_DTYPE_PARAM, &charset_form, 0, OCI_ATTR_CHARSET_FORM, S->err));
|
||||
}
|
||||
|
||||
|
||||
if (dtype) {
|
||||
// if there is a declared type
|
||||
/* if there is a declared type */
|
||||
switch (dtype) {
|
||||
#ifdef SQLT_TIMESTAMP
|
||||
case SQLT_TIMESTAMP:
|
||||
@ -870,9 +883,16 @@ static int oci_stmt_col_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_val
|
||||
add_assoc_string(return_value, "oci:decl_type", "DATE");
|
||||
add_assoc_string(return_value, "native_type", "DATE");
|
||||
break;
|
||||
case SQLT_FLT :
|
||||
case SQLT_NUM:
|
||||
add_assoc_string(return_value, "oci:decl_type", "NUMBER");
|
||||
add_assoc_string(return_value, "native_type", "NUMBER");
|
||||
/* if the precision is nonzero and scale is -127 then it is a FLOAT */
|
||||
if(scale == -127 && precis != 0){
|
||||
add_assoc_string(return_value, "oci:decl_type", "FLOAT");
|
||||
add_assoc_string(return_value, "native_type", "FLOAT");
|
||||
}else{
|
||||
add_assoc_string(return_value, "oci:decl_type", "NUMBER");
|
||||
add_assoc_string(return_value, "native_type", "NUMBER");
|
||||
}
|
||||
break;
|
||||
case SQLT_LNG:
|
||||
add_assoc_string(return_value, "oci:decl_type", "LONG");
|
||||
@ -887,12 +907,23 @@ static int oci_stmt_col_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_val
|
||||
add_assoc_string(return_value, "native_type", "LONG RAW");
|
||||
break;
|
||||
case SQLT_CHR:
|
||||
add_assoc_string(return_value, "oci:decl_type", "VARCHAR2");
|
||||
add_assoc_string(return_value, "native_type", "VARCHAR2");
|
||||
case SQLT_VCS:
|
||||
if(charset_form == SQLCS_NCHAR){
|
||||
add_assoc_string(return_value, "oci:decl_type", "NVARCHAR2");
|
||||
add_assoc_string(return_value, "native_type", "NVARCHAR2");
|
||||
}else{
|
||||
add_assoc_string(return_value, "oci:decl_type", "VARCHAR2");
|
||||
add_assoc_string(return_value, "native_type", "VARCHAR2");
|
||||
}
|
||||
break;
|
||||
case SQLT_AFC:
|
||||
add_assoc_string(return_value, "oci:decl_type", "CHAR");
|
||||
add_assoc_string(return_value, "native_type", "CHAR");
|
||||
if(charset_form == SQLCS_NCHAR){
|
||||
add_assoc_string(return_value, "oci:decl_type", "NCHAR");
|
||||
add_assoc_string(return_value, "native_type", "NCHAR");
|
||||
}else{
|
||||
add_assoc_string(return_value, "oci:decl_type", "CHAR");
|
||||
add_assoc_string(return_value, "native_type", "CHAR");
|
||||
}
|
||||
break;
|
||||
case SQLT_BLOB:
|
||||
add_assoc_string(return_value, "oci:decl_type", "BLOB");
|
||||
@ -900,9 +931,14 @@ static int oci_stmt_col_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_val
|
||||
add_assoc_string(return_value, "native_type", "BLOB");
|
||||
break;
|
||||
case SQLT_CLOB:
|
||||
add_assoc_string(return_value, "oci:decl_type", "CLOB");
|
||||
if(charset_form == SQLCS_NCHAR){
|
||||
add_assoc_string(return_value, "oci:decl_type", "NCLOB");
|
||||
add_assoc_string(return_value, "native_type", "NCLOB");
|
||||
}else{
|
||||
add_assoc_string(return_value, "oci:decl_type", "CLOB");
|
||||
add_assoc_string(return_value, "native_type", "CLOB");
|
||||
}
|
||||
add_next_index_string(&flags, "blob");
|
||||
add_assoc_string(return_value, "native_type", "CLOB");
|
||||
break;
|
||||
case SQLT_BFILE:
|
||||
add_assoc_string(return_value, "oci:decl_type", "BFILE");
|
||||
@ -913,26 +949,25 @@ static int oci_stmt_col_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_val
|
||||
add_assoc_string(return_value, "oci:decl_type", "ROWID");
|
||||
add_assoc_string(return_value, "native_type", "ROWID");
|
||||
break;
|
||||
case SQLT_FLT :
|
||||
case SQLT_BFLOAT:
|
||||
case SQLT_IBFLOAT:
|
||||
add_assoc_string(return_value, "oci:decl_type", "FLOAT");
|
||||
add_assoc_string(return_value, "native_type", "FLOAT");
|
||||
add_assoc_string(return_value, "oci:decl_type", "BINARY_FLOAT");
|
||||
add_assoc_string(return_value, "native_type", "BINARY_FLOAT");
|
||||
break;
|
||||
case SQLT_BDOUBLE:
|
||||
case SQLT_IBDOUBLE:
|
||||
add_assoc_string(return_value, "oci:decl_type", "DOUBLE");
|
||||
add_assoc_string(return_value, "native_type", "DOUBLE");
|
||||
add_assoc_string(return_value, "oci:decl_type", "BINARY_DOUBLE");
|
||||
add_assoc_string(return_value, "native_type", "BINARY_DOUBLE");
|
||||
break;
|
||||
default:
|
||||
add_assoc_long(return_value, "oci:decl_type", dtype);
|
||||
add_assoc_string(return_value, "native_type", "UNKNOWN");
|
||||
}
|
||||
} else if (data_size) {
|
||||
// if the column is the result of a function
|
||||
/* if the column is the result of a function */
|
||||
add_assoc_string(return_value, "native_type", "UNKNOWN");
|
||||
} else {
|
||||
// if the column is NULL
|
||||
/* if the column is NULL */
|
||||
add_assoc_long(return_value, "oci:decl_type", 0);
|
||||
add_assoc_string(return_value, "native_type", "NULL");
|
||||
}
|
||||
@ -941,14 +976,6 @@ static int oci_stmt_col_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_val
|
||||
STMT_CALL_MSG(OCIAttrGet, "OCI_ATTR_IS_NULL",
|
||||
(param, OCI_DTYPE_PARAM, &isnull, 0, OCI_ATTR_IS_NULL, S->err));
|
||||
|
||||
/* column name */
|
||||
STMT_CALL_MSG(OCIAttrGet, "OCI_ATTR_NAME",
|
||||
(param, OCI_DTYPE_PARAM, &colname, (ub4 *) &namelen, OCI_ATTR_NAME, S->err));
|
||||
|
||||
add_assoc_long(return_value, "precision", precis);
|
||||
add_assoc_long(return_value, "len", data_size);
|
||||
add_assoc_string(return_value, "name", (char *) colname);
|
||||
|
||||
if (isnull) {
|
||||
add_next_index_string(&flags, "nullable");
|
||||
} else {
|
||||
@ -962,12 +989,12 @@ static int oci_stmt_col_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_val
|
||||
case SQLT_CLOB:
|
||||
add_assoc_long(return_value, "pdo_type", PDO_PARAM_LOB);
|
||||
break;
|
||||
case SQLT_BIN:
|
||||
default:
|
||||
add_assoc_long(return_value, "pdo_type", PDO_PARAM_STR);
|
||||
}
|
||||
|
||||
add_assoc_zval(return_value, "flags", &flags);
|
||||
|
||||
OCIDescriptorFree(param, OCI_DTYPE_PARAM);
|
||||
return SUCCESS;
|
||||
} /* }}} */
|
||||
|
@ -8,27 +8,31 @@ PDOTest::skip();
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
echo "Preparations before the test\n";
|
||||
|
||||
require(dirname(__FILE__) . '/../../pdo/tests/pdo_test.inc');
|
||||
$db = PDOTest::factory();
|
||||
$db->exec(<<<SQL
|
||||
try {
|
||||
$db = PDOTest::factory();
|
||||
$db->exec(<<<SQL
|
||||
BEGIN
|
||||
EXECUTE IMMEDIATE 'DROP TABLE test';
|
||||
EXCEPTION
|
||||
WHEN OTHERS THEN
|
||||
IF SQLCODE != -942 THEN
|
||||
RAISE;
|
||||
RAISE;
|
||||
END IF;
|
||||
END;
|
||||
SQL
|
||||
);
|
||||
$db->exec("CREATE TABLE test(id INT)");
|
||||
$db->exec("CREATE TABLE test(id INT)");
|
||||
|
||||
$db->beginTransaction();
|
||||
|
||||
try {
|
||||
$db->beginTransaction();
|
||||
|
||||
$stmt = $db->prepare('SELECT id FROM test ORDER BY id ASC');
|
||||
|
||||
echo "Test 1. calling function with invalid parameters\n";
|
||||
|
||||
// execute() has not been called yet
|
||||
// NOTE: no warning
|
||||
if (false !== ($tmp = $stmt->getColumnMeta(0)))
|
||||
@ -51,9 +55,12 @@ try {
|
||||
if (false !== ($tmp = @$stmt->getColumnMeta(1, 1)))
|
||||
printf("[006] Expecting false got %s\n", var_export($tmp, true));
|
||||
|
||||
$emulated = $stmt->getColumnMeta(0);
|
||||
// invalid offset
|
||||
if (false !== ($tmp = $stmt->getColumnMeta(1)))
|
||||
printf("[007] Expecting false because of invalid offset got %s\n", var_export($tmp, true));
|
||||
|
||||
printf("Testing native PS...\n");
|
||||
echo "Test 2. testing return values\n";
|
||||
echo "Test 2.1 testing array returned\n";
|
||||
|
||||
$stmt = $db->prepare('SELECT id FROM test ORDER BY id ASC');
|
||||
$stmt->execute();
|
||||
@ -63,11 +70,6 @@ try {
|
||||
var_export($native, true), var_export($emulated, true));
|
||||
}
|
||||
|
||||
// invalid offset
|
||||
if (false !== ($tmp = $stmt->getColumnMeta(1)))
|
||||
printf("[009] Expecting false because of invalid offset got %s\n", var_export($tmp, true));
|
||||
|
||||
|
||||
function test_meta(&$db, $offset, $sql_type, $value, $native_type, $pdo_type) {
|
||||
|
||||
$db->exec(<<<SQL
|
||||
@ -83,10 +85,8 @@ SQL
|
||||
);
|
||||
|
||||
$sql = sprintf('CREATE TABLE test(id INT, label %s)', $sql_type);
|
||||
if (!($stmt = @$db->prepare($sql)) || (!@$stmt->execute())) {
|
||||
// Some engines might not support the data type
|
||||
return true;
|
||||
}
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
if (!$db->exec(sprintf("INSERT INTO test(id, label) VALUES (1, '%s')", $value))) {
|
||||
printf("[%03d] + 1] Insert failed, %d - %s\n", $offset,
|
||||
@ -104,7 +104,6 @@ SQL
|
||||
$stmt->errorCode(), var_export($stmt->errorInfo(), true));
|
||||
return false;
|
||||
}
|
||||
|
||||
$elements = array('flags', 'name', 'len', 'precision', 'pdo_type');
|
||||
foreach ($elements as $k => $element)
|
||||
if (!isset($meta[$element])) {
|
||||
@ -115,7 +114,7 @@ SQL
|
||||
|
||||
if (!is_null($native_type)) {
|
||||
if (!isset($meta['native_type'])) {
|
||||
printf("[%03d + 5] Element native_type missing, %s\n", $offset,
|
||||
printf("[%03d + 4] Element native_type missing, %s\n", $offset,
|
||||
var_export($meta, true));
|
||||
return false;
|
||||
}
|
||||
@ -132,7 +131,7 @@ SQL
|
||||
}
|
||||
|
||||
if (!$found) {
|
||||
printf("[%03d + 6] Expecting native type %s, %s\n", $offset,
|
||||
printf("[%03d + 5] Expecting native type %s, %s\n", $offset,
|
||||
var_export($native_type, true), var_export($meta, true));
|
||||
return false;
|
||||
}
|
||||
@ -147,51 +146,57 @@ SQL
|
||||
return true;
|
||||
}
|
||||
|
||||
test_meta($db, 10, 'NUMBER' , 0 , 'NUMBER', PDO::PARAM_STR);
|
||||
test_meta($db, 20, 'NUMBER' , 256 , 'NUMBER', PDO::PARAM_STR);
|
||||
test_meta($db, 20, 'NUMBER' , 256 , 'NUMBER', PDO::PARAM_STR);
|
||||
test_meta($db, 20, 'INT' , 256 , 'NUMBER', PDO::PARAM_STR);
|
||||
test_meta($db, 20, 'INTEGER' , 256 , 'NUMBER', PDO::PARAM_STR);
|
||||
test_meta($db, 20, 'NUMBER' , 256.01 , 'NUMBER', PDO::PARAM_STR);
|
||||
test_meta($db, 30, 'NUMBER' , -8388608 , 'NUMBER', PDO::PARAM_STR);
|
||||
echo "Test 2.2 testing numeric columns\n";
|
||||
|
||||
test_meta($db, 40, 'NUMBER' , 2147483648 , 'NUMBER', PDO::PARAM_STR);
|
||||
test_meta($db, 50, 'NUMBER' , 4294967295 , 'NUMBER', PDO::PARAM_STR);
|
||||
test_meta($db, 20, 'NUMBER' , 0 , 'NUMBER', PDO::PARAM_STR);
|
||||
test_meta($db, 30, 'NUMBER' , 256 , 'NUMBER', PDO::PARAM_STR);
|
||||
test_meta($db, 40, 'INT' , 256 , 'NUMBER', PDO::PARAM_STR);
|
||||
test_meta($db, 50, 'INTEGER' , 256 , 'NUMBER', PDO::PARAM_STR);
|
||||
test_meta($db, 60, 'NUMBER' , 256.01 , 'NUMBER', PDO::PARAM_STR);
|
||||
test_meta($db, 70, 'NUMBER' , -8388608 , 'NUMBER', PDO::PARAM_STR);
|
||||
|
||||
test_meta($db, 60, 'DECIMAL' , 1.01 , 'NUMBER', PDO::PARAM_STR);
|
||||
test_meta($db, 60, 'FLOAT' , 1.01 , 'NUMBER', PDO::PARAM_STR);
|
||||
test_meta($db, 70, 'DOUBLE' , 1.01 , 'NUMBER', PDO::PARAM_STR);
|
||||
test_meta($db, 60, 'BINARY_FLOAT' , 1.01 , 'FLOAT', PDO::PARAM_STR);
|
||||
test_meta($db, 70, 'BINARY_DOUBLE' , 1.01 , 'DOUBLE', PDO::PARAM_STR);
|
||||
test_meta($db, 80, 'NUMBER' , 2147483648 , 'NUMBER', PDO::PARAM_STR);
|
||||
test_meta($db, 90, 'NUMBER' , 4294967295 , 'NUMBER', PDO::PARAM_STR);
|
||||
|
||||
test_meta($db, 80, 'DATE' , '2008-04-23' , 'DATE', PDO::PARAM_STR);
|
||||
test_meta($db, 90, 'TIME' , '14:37:00' , 'TIME', PDO::PARAM_STR);
|
||||
test_meta($db, 110, 'YEAR' , '2008' , 'YEAR', PDO::PARAM_STR);
|
||||
test_meta($db, 100, 'DEC' , 1.01 , 'NUMBER' , PDO::PARAM_STR);
|
||||
test_meta($db, 110, 'DECIMAL' , 1.01 , 'NUMBER' , PDO::PARAM_STR);
|
||||
test_meta($db, 120, 'FLOAT' , 1.01 , 'FLOAT' , PDO::PARAM_STR);
|
||||
test_meta($db, 130, 'DOUBLE PRECISION', 1.01 , 'FLOAT' , PDO::PARAM_STR);
|
||||
test_meta($db, 140, 'BINARY_FLOAT' , 1.01 , 'BINARY_FLOAT' , PDO::PARAM_STR);
|
||||
test_meta($db, 150, 'BINARY_DOUBLE' , 1.01 , 'BINARY_DOUBLE', PDO::PARAM_STR);
|
||||
|
||||
test_meta($db, 120, 'CHAR(1)' , 'a' , 'CHAR', PDO::PARAM_STR);
|
||||
test_meta($db, 130, 'CHAR(10)' , '0123456789' , 'CHAR', PDO::PARAM_STR);
|
||||
test_meta($db, 140, 'CHAR(255)' , str_repeat('z', 255) , 'CHAR', PDO::PARAM_STR);
|
||||
test_meta($db, 150, 'VARCHAR(1)' , 'a' , 'VARCHAR2', PDO::PARAM_STR);
|
||||
test_meta($db, 160, 'VARCHAR(10)' , '0123456789' , 'VARCHAR2', PDO::PARAM_STR);
|
||||
test_meta($db, 170, 'VARCHAR(255)' , str_repeat('z', 255) , 'VARCHAR2', PDO::PARAM_STR);
|
||||
test_meta($db, 180, 'VARCHAR2(1)' , 'a' , 'VARCHAR2', PDO::PARAM_STR);
|
||||
test_meta($db, 190, 'VARCHAR2(10)' , '0123456789' , 'VARCHAR2', PDO::PARAM_STR);
|
||||
test_meta($db, 200, 'VARCHAR2(255)' , str_repeat('z', 255) , 'VARCHAR2', PDO::PARAM_STR);
|
||||
echo "Test 2.3 testing temporal columns\n";
|
||||
|
||||
test_meta($db, 210, 'NCHAR(1)' , 'a' , 'CHAR', PDO::PARAM_STR);
|
||||
test_meta($db, 220, 'NCHAR(10)' , '0123456789' , 'CHAR', PDO::PARAM_STR);
|
||||
test_meta($db, 230, 'NCHAR(255)' , str_repeat('z', 255) , 'CHAR', PDO::PARAM_STR);
|
||||
test_meta($db, 240, 'NVARCHAR2(1)' , 'a' , 'VARCHAR2', PDO::PARAM_STR);
|
||||
test_meta($db, 250, 'NVARCHAR2(10)' , '0123456789' , 'VARCHAR2', PDO::PARAM_STR);
|
||||
test_meta($db, 260, 'NVARCHAR2(255)', str_repeat('z', 255) , 'VARCHAR2', PDO::PARAM_STR);
|
||||
test_meta($db, 160, 'DATE' , '2008-04-23' , 'DATE', PDO::PARAM_STR);
|
||||
|
||||
test_meta($db, 270, 'CLOB' , str_repeat('b', 255) , 'CLOB', PDO::PARAM_LOB);
|
||||
test_meta($db, 280, 'BLOB' , str_repeat('b', 256) , 'BLOB', PDO::PARAM_LOB);
|
||||
test_meta($db, 290, 'NCLOB' , str_repeat('b', 255) , 'CLOB', PDO::PARAM_LOB);
|
||||
echo "Test 2.4 testing string columns\n";
|
||||
|
||||
test_meta($db, 300, 'LONG' , str_repeat('b', 256) , 'LONG', PDO::PARAM_STR);
|
||||
test_meta($db, 310, 'LONG RAW' , str_repeat('b', 256) , 'LONG RAW', PDO::PARAM_STR);
|
||||
test_meta($db, 320, 'RAW' , str_repeat('b', 256) , 'RAW', PDO::PARAM_STR);
|
||||
test_meta($db, 170, 'CHAR(1)' , 'a' , 'CHAR' , PDO::PARAM_STR);
|
||||
test_meta($db, 180, 'CHAR(10)' , '0123456789' , 'CHAR' , PDO::PARAM_STR);
|
||||
test_meta($db, 190, 'CHAR(255)' , str_repeat('z', 255) , 'CHAR' , PDO::PARAM_STR);
|
||||
test_meta($db, 200, 'VARCHAR(1)' , 'a' , 'VARCHAR2' , PDO::PARAM_STR);
|
||||
test_meta($db, 210, 'VARCHAR(10)' , '0123456789' , 'VARCHAR2' , PDO::PARAM_STR);
|
||||
test_meta($db, 220, 'VARCHAR(255)' , str_repeat('z', 255) , 'VARCHAR2' , PDO::PARAM_STR);
|
||||
test_meta($db, 230, 'VARCHAR2(1)' , 'a' , 'VARCHAR2' , PDO::PARAM_STR);
|
||||
test_meta($db, 240, 'VARCHAR2(10)' , '0123456789' , 'VARCHAR2' , PDO::PARAM_STR);
|
||||
test_meta($db, 250, 'VARCHAR2(255)' , str_repeat('z', 255) , 'VARCHAR2' , PDO::PARAM_STR);
|
||||
|
||||
test_meta($db, 260, 'NCHAR(1)' , 'a' , 'NCHAR' , PDO::PARAM_STR);
|
||||
test_meta($db, 270, 'NCHAR(10)' , '0123456789' , 'NCHAR' , PDO::PARAM_STR);
|
||||
test_meta($db, 280, 'NCHAR(255)' , str_repeat('z', 255) , 'NCHAR' , PDO::PARAM_STR);
|
||||
test_meta($db, 290, 'NVARCHAR2(1)' , 'a' , 'NVARCHAR2', PDO::PARAM_STR);
|
||||
test_meta($db, 300, 'NVARCHAR2(10)' , '0123456789' , 'NVARCHAR2', PDO::PARAM_STR);
|
||||
test_meta($db, 310, 'NVARCHAR2(255)', str_repeat('z', 255) , 'NVARCHAR2', PDO::PARAM_STR);
|
||||
|
||||
echo "Test 2.5 testing lobs columns\n";
|
||||
|
||||
test_meta($db, 320, 'CLOB' , str_repeat('b', 255) , 'CLOB' , PDO::PARAM_LOB);
|
||||
test_meta($db, 330, 'BLOB' , str_repeat('b', 256) , 'BLOB' , PDO::PARAM_LOB);
|
||||
test_meta($db, 340, 'NCLOB' , str_repeat('b', 255) , 'NCLOB' , PDO::PARAM_LOB);
|
||||
|
||||
test_meta($db, 350, 'LONG' , str_repeat('b', 256) , 'LONG' , PDO::PARAM_STR);
|
||||
test_meta($db, 360, 'LONG RAW' , str_repeat('b', 256) , 'LONG RAW', PDO::PARAM_STR);
|
||||
test_meta($db, 370, 'RAW(256)' , str_repeat('b', 256) , 'RAW' , PDO::PARAM_STR);
|
||||
|
||||
$db->exec(<<<SQL
|
||||
BEGIN
|
||||
@ -204,40 +209,44 @@ EXCEPTION
|
||||
END;
|
||||
SQL
|
||||
);
|
||||
echo "Test 2.6 testing flags returned\n";
|
||||
|
||||
$sql = sprintf('CREATE TABLE test(id INT NOT NULL, label INT NULL)');
|
||||
if (($stmt = $db->prepare($sql)) && $stmt->execute()) {
|
||||
$db->exec('INSERT INTO test(id, label) VALUES (1, 1)');
|
||||
$stmt = $db->query('SELECT id, label FROM test');
|
||||
$meta = $stmt->getColumnMeta(0);
|
||||
if (!isset($meta['flags'])) {
|
||||
printf("[1002] No flags contained in metadata %s\n", var_export($meta, true));
|
||||
} else {
|
||||
$flags = $meta['flags'];
|
||||
$found = false;
|
||||
foreach ($flags as $k => $flag) {
|
||||
if ($flag == 'not_null')
|
||||
$found = true;
|
||||
if ($flag == 'nullable')
|
||||
printf("[1003] Flags seem wrong %s\n", var_export($meta, true));
|
||||
}
|
||||
if (!$found)
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->execute();
|
||||
$db->exec('INSERT INTO test(id, label) VALUES (1, 1)');
|
||||
$stmt = $db->query('SELECT id, label FROM test');
|
||||
$meta = $stmt->getColumnMeta(0);
|
||||
// verify the flags array countains a not_null flag and not nullable flags
|
||||
if (!isset($meta['flags'])) {
|
||||
printf("[1001] No flags contained in metadata %s\n", var_export($meta, true));
|
||||
} else {
|
||||
$flags = $meta['flags'];
|
||||
$found = false;
|
||||
foreach ($flags as $k => $flag) {
|
||||
if ($flag == 'not_null')
|
||||
$found = true;
|
||||
if ($flag == 'nullable')
|
||||
printf("[1003] Flags seem wrong %s\n", var_export($meta, true));
|
||||
}
|
||||
$meta = $stmt->getColumnMeta(1);
|
||||
if (!isset($meta['flags'])) {
|
||||
printf("[1002] No flags contained in metadata %s\n", var_export($meta, true));
|
||||
} else {
|
||||
$flags = $meta['flags'];
|
||||
$found = false;
|
||||
foreach ($flags as $k => $flag) {
|
||||
if ($flag == 'not_null')
|
||||
printf("[1003] Flags seem wrong %s\n", var_export($meta, true));
|
||||
if ($flag == 'nullable')
|
||||
$found = true;
|
||||
}
|
||||
if (!$found)
|
||||
printf("[1003] Flags seem wrong %s\n", var_export($meta, true));
|
||||
if (!$found)
|
||||
printf("[1002] Flags seem wrong %s\n", var_export($meta, true));
|
||||
}
|
||||
$meta = $stmt->getColumnMeta(1);
|
||||
// verify the flags array countains a nullable flag and not not_null flags
|
||||
if (!isset($meta['flags'])) {
|
||||
printf("[1003] No flags contained in metadata %s\n", var_export($meta, true));
|
||||
} else {
|
||||
$flags = $meta['flags'];
|
||||
$found = false;
|
||||
foreach ($flags as $k => $flag) {
|
||||
if ($flag == 'not_null')
|
||||
printf("[1004] Flags seem wrong %s\n", var_export($meta, true));
|
||||
if ($flag == 'nullable')
|
||||
$found = true;
|
||||
}
|
||||
if (!$found)
|
||||
printf("[1005] Flags seem wrong %s\n", var_export($meta, true));
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
@ -260,5 +269,13 @@ SQL
|
||||
print "done!";
|
||||
?>
|
||||
--EXPECT--
|
||||
Testing native PS...
|
||||
Preparations before the test
|
||||
Test 1. calling function with invalid parameters
|
||||
Test 2. testing return values
|
||||
Test 2.1 testing array returned
|
||||
Test 2.2 testing numeric columns
|
||||
Test 2.3 testing temporal columns
|
||||
Test 2.4 testing string columns
|
||||
Test 2.5 testing lobs columns
|
||||
Test 2.6 testing flags returned
|
||||
done!
|
||||
|
Loading…
Reference in New Issue
Block a user