1 | <?php |
---|
2 | /* |
---|
3 | V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). 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. |
---|
8 | |
---|
9 | Latest version is available at http://adodb.sourceforge.net |
---|
10 | |
---|
11 | SAPDB data driver. Requires ODBC. |
---|
12 | |
---|
13 | */ |
---|
14 | |
---|
15 | // security - hide paths |
---|
16 | if (!defined('ADODB_DIR')) die(); |
---|
17 | |
---|
18 | if (!defined('_ADODB_ODBC_LAYER')) { |
---|
19 | include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); |
---|
20 | } |
---|
21 | if (!defined('ADODB_SAPDB')){ |
---|
22 | define('ADODB_SAPDB',1); |
---|
23 | |
---|
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; |
---|
33 | |
---|
34 | function ADODB_SAPDB() |
---|
35 | { |
---|
36 | //if (strncmp(PHP_OS,'WIN',3) === 0) $this->curmode = SQL_CUR_USE_ODBC; |
---|
37 | $this->ADODB_odbc(); |
---|
38 | } |
---|
39 | |
---|
40 | function ServerInfo() |
---|
41 | { |
---|
42 | $info = ADODB_odbc::ServerInfo(); |
---|
43 | if (!$info['version'] && preg_match('/([0-9.]+)/',$info['description'],$matches)) { |
---|
44 | $info['version'] = $matches[1]; |
---|
45 | } |
---|
46 | return $info; |
---|
47 | } |
---|
48 | |
---|
49 | function MetaPrimaryKeys($table) |
---|
50 | { |
---|
51 | $table = $this->Quote(strtoupper($table)); |
---|
52 | |
---|
53 | return $this->GetCol("SELECT columnname FROM COLUMNS WHERE tablename=$table AND mode='KEY' ORDER BY pos"); |
---|
54 | } |
---|
55 | |
---|
56 | function &MetaIndexes ($table, $primary = FALSE) |
---|
57 | { |
---|
58 | $table = $this->Quote(strtoupper($table)); |
---|
59 | |
---|
60 | $sql = "SELECT INDEXNAME,TYPE,COLUMNNAME FROM INDEXCOLUMNS ". |
---|
61 | " WHERE TABLENAME=$table". |
---|
62 | " ORDER BY INDEXNAME,COLUMNNO"; |
---|
63 | |
---|
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); |
---|
69 | } |
---|
70 | |
---|
71 | $rs = $this->Execute($sql); |
---|
72 | if (isset($savem)) { |
---|
73 | $this->SetFetchMode($savem); |
---|
74 | } |
---|
75 | $ADODB_FETCH_MODE = $save; |
---|
76 | |
---|
77 | if (!is_object($rs)) { |
---|
78 | return FALSE; |
---|
79 | } |
---|
80 | |
---|
81 | $indexes = array(); |
---|
82 | while ($row = $rs->FetchRow()) { |
---|
83 | $indexes[$row[0]]['unique'] = $row[1] == 'UNIQUE'; |
---|
84 | $indexes[$row[0]]['columns'][] = $row[2]; |
---|
85 | } |
---|
86 | if ($primary) { |
---|
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"), |
---|
90 | ); |
---|
91 | } |
---|
92 | return $indexes; |
---|
93 | } |
---|
94 | |
---|
95 | function &MetaColumns ($table) |
---|
96 | { |
---|
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); |
---|
102 | } |
---|
103 | $table = $this->Quote(strtoupper($table)); |
---|
104 | |
---|
105 | $retarr = array(); |
---|
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) |
---|
107 | { |
---|
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; |
---|
119 | } else { |
---|
120 | $fld->default_value = $column[6]; |
---|
121 | switch($fld->type) { |
---|
122 | case 'VARCHAR': |
---|
123 | case 'CHARACTER': |
---|
124 | case 'LONG': |
---|
125 | $fld->default_value = $column[6]; |
---|
126 | break; |
---|
127 | default: |
---|
128 | $fld->default_value = trim($column[6]); |
---|
129 | break; |
---|
130 | } |
---|
131 | } |
---|
132 | } |
---|
133 | $retarr[$fld->name] = $fld; |
---|
134 | } |
---|
135 | if (isset($savem)) { |
---|
136 | $this->SetFetchMode($savem); |
---|
137 | } |
---|
138 | $ADODB_FETCH_MODE = $save; |
---|
139 | |
---|
140 | return $retarr; |
---|
141 | } |
---|
142 | |
---|
143 | function MetaColumnNames($table) |
---|
144 | { |
---|
145 | $table = $this->Quote(strtoupper($table)); |
---|
146 | |
---|
147 | return $this->GetCol("SELECT columnname FROM COLUMNS WHERE tablename=$table ORDER BY pos"); |
---|
148 | } |
---|
149 | |
---|
150 | // unlike it seems, this depends on the db-session and works in a multiuser environment |
---|
151 | function _insertid($table,$column) |
---|
152 | { |
---|
153 | return empty($table) ? False : $this->GetOne("SELECT $table.CURRVAL FROM DUAL"); |
---|
154 | } |
---|
155 | |
---|
156 | /* |
---|
157 | SelectLimit implementation problems: |
---|
158 | |
---|
159 | The following will return random 10 rows as order by performed after "WHERE rowno<10" |
---|
160 | which is not ideal... |
---|
161 | |
---|
162 | select * from table where rowno < 10 order by 1 |
---|
163 | |
---|
164 | This means that we have to use the adoconnection base class SelectLimit when |
---|
165 | there is an "order by". |
---|
166 | |
---|
167 | See http://listserv.sap.com/pipermail/sapdb.general/2002-January/010405.html |
---|
168 | */ |
---|
169 | |
---|
170 | }; |
---|
171 | |
---|
172 | |
---|
173 | class ADORecordSet_sapdb extends ADORecordSet_odbc { |
---|
174 | |
---|
175 | var $databaseType = "sapdb"; |
---|
176 | |
---|
177 | function ADORecordSet_sapdb($id,$mode=false) |
---|
178 | { |
---|
179 | $this->ADORecordSet_odbc($id,$mode); |
---|
180 | } |
---|
181 | } |
---|
182 | |
---|
183 | } //define |
---|
184 | ?> |
---|