mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-06-24 20:01:36 +02:00
added own MetaType, MetaColumns and MetaColumnNames functions for MaxDB to have better control over the column-types
This commit is contained in:
parent
647222728c
commit
ee3f5cafff
@ -49,6 +49,36 @@ class ADODB2_sapdb extends ADODB_DataDict {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function MetaType($t,$len=-1,$fieldobj=false)
|
||||||
|
{
|
||||||
|
if (is_object($t)) {
|
||||||
|
$fieldobj = $t;
|
||||||
|
$t = $fieldobj->type;
|
||||||
|
$len = $fieldobj->max_length;
|
||||||
|
}
|
||||||
|
static $maxdb_type2adodb = array(
|
||||||
|
'VARCHAR' => 'C',
|
||||||
|
'CHARACTER' => 'C',
|
||||||
|
'LONG' => 'X', // no way to differ between 'X' and 'B' :-(
|
||||||
|
'DATE' => 'D',
|
||||||
|
'TIMESTAMP' => 'T',
|
||||||
|
'BOOLEAN' => 'L',
|
||||||
|
'INTEGER' => 'I4',
|
||||||
|
'SMALLINT' => 'I2',
|
||||||
|
'FLOAT' => 'F',
|
||||||
|
'FIXED' => 'N',
|
||||||
|
);
|
||||||
|
$type = isset($maxdb_type2adodb[$t]) ? $maxdb_type2adodb[$t] : 'C';
|
||||||
|
|
||||||
|
// convert integer-types simulated with fixed back to integer
|
||||||
|
if ($t == 'FIXED' && !$fieldobj->scale && ($len == 20 || $len == 3)) {
|
||||||
|
$type = $len == 20 ? 'I8' : 'I1';
|
||||||
|
}
|
||||||
|
if ($fieldobj->auto_increment) $type = 'R';
|
||||||
|
|
||||||
|
return $type;
|
||||||
|
}
|
||||||
|
|
||||||
// return string must begin with space
|
// return string must begin with space
|
||||||
function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
|
function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
|
||||||
{
|
{
|
||||||
|
@ -60,15 +60,16 @@ class ADODB_SAPDB extends ADODB_odbc {
|
|||||||
" WHERE TABLENAME=$table".
|
" WHERE TABLENAME=$table".
|
||||||
" ORDER BY INDEXNAME,COLUMNNO";
|
" ORDER BY INDEXNAME,COLUMNNO";
|
||||||
|
|
||||||
|
global $ADODB_FETCH_MODE;
|
||||||
$save = $ADODB_FETCH_MODE;
|
$save = $ADODB_FETCH_MODE;
|
||||||
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||||
if ($this->fetchMode !== FALSE) {
|
if ($this->fetchMode !== FALSE) {
|
||||||
$savem = $this->SetFetchMode(FALSE);
|
$savem = $this->SetFetchMode(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
$rs = $this->Execute($sql);
|
$rs = $this->Execute($sql);
|
||||||
if (isset($savem)) {
|
if (isset($savem)) {
|
||||||
$this->SetFetchMode($savem);
|
$this->SetFetchMode($savem);
|
||||||
}
|
}
|
||||||
$ADODB_FETCH_MODE = $save;
|
$ADODB_FETCH_MODE = $save;
|
||||||
|
|
||||||
@ -89,7 +90,52 @@ class ADODB_SAPDB extends ADODB_odbc {
|
|||||||
}
|
}
|
||||||
return $indexes;
|
return $indexes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function &MetaColumns ($table)
|
||||||
|
{
|
||||||
|
global $ADODB_FETCH_MODE;
|
||||||
|
$save = $ADODB_FETCH_MODE;
|
||||||
|
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||||
|
if ($this->fetchMode !== FALSE) {
|
||||||
|
$savem = $this->SetFetchMode(FALSE);
|
||||||
|
}
|
||||||
|
$table = $this->Quote(strtoupper($table));
|
||||||
|
|
||||||
|
$retarr = array();
|
||||||
|
foreach($this->GetAll("SELECT COLUMNNAME,DATATYPE,LEN,DEC,NULLABLE,MODE,\"DEFAULT\",CASE WHEN \"DEFAULT\" IS NULL THEN 0 ELSE 1 END AS HAS_DEFAULT FROM COLUMNS WHERE tablename=$table ORDER BY pos") as $column)
|
||||||
|
{
|
||||||
|
$fld = new ADOFieldObject();
|
||||||
|
$fld->name = $column[0];
|
||||||
|
$fld->type = $column[1];
|
||||||
|
$fld->max_length = $fld->type == 'LONG' ? 2147483647 : $column[2];
|
||||||
|
$fld->scale = $column[3];
|
||||||
|
$fld->not_null = $column[4] == 'NO';
|
||||||
|
$fld->primary_key = $column[5] == 'KEY';
|
||||||
|
if ($fld->has_default = $column[7]) {
|
||||||
|
if ($fld->primary_key && $column[6] == 'DEFAULT SERIAL (1)') {
|
||||||
|
$fld->auto_increment = true;
|
||||||
|
$fld->has_default = false;
|
||||||
|
} else {
|
||||||
|
$fld->default_value = $column[6];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$retarr[$fld->name] = $fld;
|
||||||
|
}
|
||||||
|
if (isset($savem)) {
|
||||||
|
$this->SetFetchMode($savem);
|
||||||
|
}
|
||||||
|
$ADODB_FETCH_MODE = $save;
|
||||||
|
|
||||||
|
return $retarr;
|
||||||
|
}
|
||||||
|
|
||||||
|
function MetaColumnNames($table)
|
||||||
|
{
|
||||||
|
$table = $this->Quote(strtoupper($table));
|
||||||
|
|
||||||
|
return $this->GetCol("SELECT columnname FROM COLUMNS WHERE tablename=$table ORDER BY pos");
|
||||||
|
}
|
||||||
|
|
||||||
// unlike it seems, this depends on the db-session and works in a multiuser environment
|
// unlike it seems, this depends on the db-session and works in a multiuser environment
|
||||||
function _insertid($table,$column)
|
function _insertid($table,$column)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user