3 V5.16 26 Mar 2012 (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved.
4 Released under both BSD license and Lesser GPL library license.
5 Whenever there is any discrepancy between the two licenses,
6 the BSD license will take precedence.
7 Set tabs to 4 for best viewing.
9 Latest version is available at http://adodb.sourceforge.net
11 SAPDB data driver. Requires ODBC.
15 // security - hide paths
16 if (!defined('ADODB_DIR')) die();
18 if (!defined('_ADODB_ODBC_LAYER')) {
19 include(ADODB_DIR
."/drivers/adodb-odbc.inc.php");
21 if (!defined('ADODB_SAPDB')){
22 define('ADODB_SAPDB',1);
24 class ADODB_SAPDB
extends ADODB_odbc
{
25 var $databaseType = "sapdb";
26 var $concat_operator = '||';
27 var $sysDate = 'DATE';
28 var $sysTimeStamp = 'TIMESTAMP';
29 var $fmtDate = "'Y-m-d'"; /// used by DBDate() as the default date format used by the database
30 var $fmtTimeStamp = "'Y-m-d H:i:s'"; /// used by DBTimeStamp as the default timestamp fmt.
31 var $hasInsertId = true;
32 var $_bindInputArray = true;
34 function ADODB_SAPDB()
36 //if (strncmp(PHP_OS,'WIN',3) === 0) $this->curmode = SQL_CUR_USE_ODBC;
42 $info = ADODB_odbc
::ServerInfo();
43 if (!$info['version'] && preg_match('/([0-9.]+)/',$info['description'],$matches)) {
44 $info['version'] = $matches[1];
49 function MetaPrimaryKeys($table)
51 $table = $this->Quote(strtoupper($table));
53 return $this->GetCol("SELECT columnname FROM COLUMNS WHERE tablename=$table AND mode='KEY' ORDER BY pos");
56 function MetaIndexes ($table, $primary = FALSE, $owner = false)
58 $table = $this->Quote(strtoupper($table));
60 $sql = "SELECT INDEXNAME,TYPE,COLUMNNAME FROM INDEXCOLUMNS ".
61 " WHERE TABLENAME=$table".
62 " ORDER BY INDEXNAME,COLUMNNO";
64 global $ADODB_FETCH_MODE;
65 $save = $ADODB_FETCH_MODE;
66 $ADODB_FETCH_MODE = ADODB_FETCH_NUM
;
67 if ($this->fetchMode
!== FALSE) {
68 $savem = $this->SetFetchMode(FALSE);
71 $rs = $this->Execute($sql);
73 $this->SetFetchMode($savem);
75 $ADODB_FETCH_MODE = $save;
77 if (!is_object($rs)) {
82 while ($row = $rs->FetchRow()) {
83 $indexes[$row[0]]['unique'] = $row[1] == 'UNIQUE';
84 $indexes[$row[0]]['columns'][] = $row[2];
87 $indexes['SYSPRIMARYKEYINDEX'] = array(
88 'unique' => True, // by definition
89 'columns' => $this->GetCol("SELECT columnname FROM COLUMNS WHERE tablename=$table AND mode='KEY' ORDER BY pos"),
95 function MetaColumns ($table)
97 global $ADODB_FETCH_MODE;
98 $save = $ADODB_FETCH_MODE;
99 $ADODB_FETCH_MODE = ADODB_FETCH_NUM
;
100 if ($this->fetchMode
!== FALSE) {
101 $savem = $this->SetFetchMode(FALSE);
103 $table = $this->Quote(strtoupper($table));
106 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)
108 $fld = new ADOFieldObject();
109 $fld->name
= $column[0];
110 $fld->type
= $column[1];
111 $fld->max_length
= $fld->type
== 'LONG' ?
2147483647 : $column[2];
112 $fld->scale
= $column[3];
113 $fld->not_null
= $column[4] == 'NO';
114 $fld->primary_key
= $column[5] == 'KEY';
115 if ($fld->has_default
= $column[7]) {
116 if ($fld->primary_key
&& $column[6] == 'DEFAULT SERIAL (1)') {
117 $fld->auto_increment
= true;
118 $fld->has_default
= false;
120 $fld->default_value
= $column[6];
125 $fld->default_value
= $column[6];
128 $fld->default_value
= trim($column[6]);
133 $retarr[$fld->name
] = $fld;
136 $this->SetFetchMode($savem);
138 $ADODB_FETCH_MODE = $save;
143 function MetaColumnNames($table)
145 $table = $this->Quote(strtoupper($table));
147 return $this->GetCol("SELECT columnname FROM COLUMNS WHERE tablename=$table ORDER BY pos");
150 // unlike it seems, this depends on the db-session and works in a multiuser environment
151 function _insertid($table,$column)
153 return empty($table) ?
False : $this->GetOne("SELECT $table.CURRVAL FROM DUAL");
157 SelectLimit implementation problems:
159 The following will return random 10 rows as order by performed after "WHERE rowno<10"
160 which is not ideal...
162 select * from table where rowno < 10 order by 1
164 This means that we have to use the adoconnection base class SelectLimit when
165 there is an "order by".
167 See http://listserv.sap.com/pipermail/sapdb.general/2002-January/010405.html
173 class ADORecordSet_sapdb
extends ADORecordSet_odbc
{
175 var $databaseType = "sapdb";
177 function ADORecordSet_sapdb($id,$mode=false)
179 $this->ADORecordSet_odbc($id,$mode);