1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-22 21:54:05 +02:00

- added dibi-field-type autodetection

- added DibiColumnInfo::getVendorInfo()
This commit is contained in:
David Grudl
2008-10-28 14:37:40 +00:00
parent 318b3093a5
commit 7565ffb1d4
9 changed files with 119 additions and 50 deletions

View File

@@ -346,9 +346,8 @@ class DibiMsSqlDriver extends DibiObject implements IDibiDriver
'name' => $row['name'],
'fullname' => $row['column_source'] ? $row['column_source'] . '.' . $row['name'] : $row['name'],
'table' => $row['column_source'],
'type' => NULL,
'nativetype' => $row['type'],
) + $row;
);
}
return $res;
}

View File

@@ -409,12 +409,12 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver
for ($i = 0; $i < $count; $i++) {
$row = (array) mysql_fetch_field($this->resultSet, $i);
$res[] = array(
'name' => $row['name'],
'table' => $row['table'],
'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'],
'type' => NULL,
'nativetype' => strtoupper($row['type']),
'nullable' => !($row['not_null']),
'default' => $row['def'],
) + $row;
'vendor' => $row,
);
}
return $res;
}

View File

@@ -386,21 +386,27 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver
*/
public function getColumnsMeta()
{
static $types;
if (empty($types)) {
$consts = get_defined_constants(TRUE);
foreach ($consts['mysqli'] as $key => $value) {
if (strncmp($key, 'MYSQLI_TYPE_', 12) === 0) {
$types[$value] = substr($key, 12);
}
}
}
$count = mysqli_num_fields($this->resultSet);
$res = array();
for ($i = 0; $i < $count; $i++) {
$row = (array) mysqli_fetch_field_direct($this->resultSet, $i);
$res[] = array(
'name' => $row['name'],
'column' => $row['orgname'],
'alias' => $row['table'],
'table' => $row['orgtable'],
'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'],
'type' => NULL,
'nativetype' => $row['type'],
'nullable' => !($row['flags'] & MYSQLI_NOT_NULL_FLAG),
'default' => $row['def'],
) + $row;
'nativetype' => $types[$row['type']],
'vendor' => $row,
);
}
return $res;
}

View File

@@ -400,10 +400,12 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver
throw new DibiDriverException('Driver does not support meta data.');
}
$res[] = array(
'type' => NULL,
'name' => $row['name'],
'table' => $row['table'],
'nativetype' => $row['native_type'],
'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'],
) + $row;
'vendor' => $row,
);
}
return $res;
}

View File

@@ -456,14 +456,14 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver
$this->query("
SELECT indkey
FROM pg_index, pg_class
WHERE pg_class.relname = '$_table' AND pg_class.oid = pg_index.indrelid AND pg_index.indisprimary
WHERE pg_class.relname = $_table AND pg_class.oid = pg_index.indrelid AND pg_index.indisprimary
");
$primary = (int) pg_fetch_object($this->resultSet)->indkey;
$this->query("
SELECT *
FROM information_schema.columns
WHERE table_name = '$_table' AND table_schema = current_schema()
WHERE table_name = $_table AND table_schema = current_schema()
ORDER BY ordinal_position
");
$res = array();
@@ -472,13 +472,13 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver
$res[] = array(
'name' => $row['column_name'],
'table' => $table,
'type' => NULL,
'nativetype' => strtoupper($row['udt_name']),
'size' => $size ? $size : NULL,
'nullable' => $row['is_nullable'] === 'YES',
'default' => $row['column_default'],
'autoincrement' => (int) $row['ordinal_position'] === $primary && substr($row['column_default'], 0, 7) === 'nextval',
) + $row;
'vendor' => $row,
);
}
$this->free();
return $res;

View File

@@ -369,6 +369,7 @@ class DibiSqliteDriver extends DibiObject implements IDibiDriver
'name' => isset($pair[1]) ? $pair[1] : $pair[0],
'table' => isset($pair[1]) ? $pair[0] : NULL,
'fullname' => $name,
'nativetype' => NULL,
);
}
return $res;