sqlite3.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Robin Appelman
  6. * @copyright 2011 Robin Appelman icewind1991@gmail.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. require_once 'MDB2/Driver/Reverse/Common.php';
  23. /**
  24. * MDB2 SQlite driver for the schema reverse engineering module
  25. *
  26. * @package MDB2
  27. * @category Database
  28. * @author Lukas Smith <smith@pooteeweet.org>
  29. */
  30. class MDB2_Driver_Reverse_sqlite3 extends MDB2_Driver_Reverse_Common
  31. {
  32. /**
  33. * Remove SQL comments from the field definition
  34. *
  35. * @access private
  36. */
  37. function _removeComments($sql) {
  38. $lines = explode("\n", $sql);
  39. foreach ($lines as $k => $line) {
  40. $pieces = explode('--', $line);
  41. if (count($pieces) > 1 && (substr_count($pieces[0], '\'') % 2) == 0) {
  42. $lines[$k] = substr($line, 0, strpos($line, '--'));
  43. }
  44. }
  45. return implode("\n", $lines);
  46. }
  47. /**
  48. *
  49. */
  50. function _getTableColumns($sql)
  51. {
  52. $db =$this->getDBInstance();
  53. if (PEAR::isError($db)) {
  54. return $db;
  55. }
  56. $start_pos = strpos($sql, '(');
  57. $end_pos = strrpos($sql, ')');
  58. $column_def = substr($sql, $start_pos+1, $end_pos-$start_pos-1);
  59. // replace the decimal length-places-separator with a colon
  60. $column_def = preg_replace('/(\d),(\d)/', '\1:\2', $column_def);
  61. $column_def = $this->_removeComments($column_def);
  62. $column_sql = explode(',', $column_def);
  63. $columns = array();
  64. $count = count($column_sql);
  65. if ($count == 0) {
  66. return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
  67. 'unexpected empty table column definition list', __FUNCTION__);
  68. }
  69. $regexp = '/^\s*([^\s]+) +(CHAR|VARCHAR|VARCHAR2|TEXT|BOOLEAN|SMALLINT|INT|INTEGER|DECIMAL|BIGINT|DOUBLE|FLOAT|DATETIME|DATE|TIME|LONGTEXT|LONGBLOB)( ?\(([1-9][0-9]*)(:([1-9][0-9]*))?\))?( NULL| NOT NULL)?( UNSIGNED)?( NULL| NOT NULL)?( PRIMARY KEY)?( AUTOINCREMENT)?( DEFAULT (\'[^\']*\'|[^ ]+))?( NULL| NOT NULL)?( PRIMARY KEY)?(\s*\-\-.*)?$/i';
  70. $regexp2 = '/^\s*([^ ]+) +(PRIMARY|UNIQUE|CHECK)$/i';
  71. for ($i=0, $j=0; $i<$count; ++$i) {
  72. if (!preg_match($regexp, trim($column_sql[$i]), $matches)) {
  73. if (!preg_match($regexp2, trim($column_sql[$i]))) {
  74. continue;
  75. }
  76. return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
  77. 'unexpected table column SQL definition: "'.$column_sql[$i].'"', __FUNCTION__);
  78. }
  79. $columns[$j]['name'] = trim($matches[1], implode('', $db->identifier_quoting));
  80. $columns[$j]['type'] = strtolower($matches[2]);
  81. if (isset($matches[4]) && strlen($matches[4])) {
  82. $columns[$j]['length'] = $matches[4];
  83. }
  84. if (isset($matches[6]) && strlen($matches[6])) {
  85. $columns[$j]['decimal'] = $matches[6];
  86. }
  87. if (isset($matches[8]) && strlen($matches[8])) {
  88. $columns[$j]['unsigned'] = true;
  89. }
  90. if (isset($matches[10]) && strlen($matches[10])) {
  91. $columns[$j]['autoincrement'] = true;
  92. $columns[$j]['notnull']=true;
  93. }
  94. if (isset($matches[10]) && strlen($matches[10])) {
  95. $columns[$j]['autoincrement'] = true;
  96. $columns[$j]['notnull']=true;
  97. }
  98. if (isset($matches[13]) && strlen($matches[13])) {
  99. $default = $matches[13];
  100. if (strlen($default) && $default[0]=="'") {
  101. $default = str_replace("''", "'", substr($default, 1, strlen($default)-2));
  102. }
  103. if ($default === 'NULL') {
  104. $default = null;
  105. }
  106. $columns[$j]['default'] = $default;
  107. }
  108. if (isset($matches[7]) && strlen($matches[7])) {
  109. $columns[$j]['notnull'] = ($matches[7] === ' NOT NULL');
  110. } else if (isset($matches[9]) && strlen($matches[9])) {
  111. $columns[$j]['notnull'] = ($matches[9] === ' NOT NULL');
  112. } else if (isset($matches[14]) && strlen($matches[14])) {
  113. $columns[$j]['notnull'] = ($matches[14] === ' NOT NULL');
  114. }
  115. ++$j;
  116. }
  117. return $columns;
  118. }
  119. // {{{ getTableFieldDefinition()
  120. /**
  121. * Get the stucture of a field into an array
  122. *
  123. * @param string $table_name name of table that should be used in method
  124. * @param string $field_name name of field that should be used in method
  125. * @return mixed data array on success, a MDB2 error on failure.
  126. * The returned array contains an array for each field definition,
  127. * with (some of) these indices:
  128. * [notnull] [nativetype] [length] [fixed] [default] [type] [mdb2type]
  129. * @access public
  130. */
  131. function getTableFieldDefinition($table_name, $field_name)
  132. {
  133. $db =$this->getDBInstance();
  134. if (PEAR::isError($db)) {
  135. return $db;
  136. }
  137. list($schema, $table) = $this->splitTableSchema($table_name);
  138. $result = $db->loadModule('Datatype', null, true);
  139. if (PEAR::isError($result)) {
  140. return $result;
  141. }
  142. $query = "SELECT sql FROM sqlite_master WHERE type='table' AND ";
  143. if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
  144. $query.= 'LOWER(name)='.$db->quote(strtolower($table), 'text');
  145. } else {
  146. $query.= 'name='.$db->quote($table, 'text');
  147. }
  148. $sql = $db->queryOne($query);
  149. if (PEAR::isError($sql)) {
  150. return $sql;
  151. }
  152. $columns = $this->_getTableColumns($sql);
  153. foreach ($columns as $column) {
  154. if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
  155. if ($db->options['field_case'] == CASE_LOWER) {
  156. $column['name'] = strtolower($column['name']);
  157. } else {
  158. $column['name'] = strtoupper($column['name']);
  159. }
  160. } else {
  161. $column = array_change_key_case($column, $db->options['field_case']);
  162. }
  163. if ($field_name == $column['name']) {
  164. $mapped_datatype = $db->datatype->mapNativeDatatype($column);
  165. if (PEAR::isError($mapped_datatype)) {
  166. return $mapped_datatype;
  167. }
  168. list($types, $length, $unsigned, $fixed) = $mapped_datatype;
  169. $notnull = false;
  170. if (!empty($column['notnull'])) {
  171. $notnull = $column['notnull'];
  172. }
  173. $default = false;
  174. if (array_key_exists('default', $column)) {
  175. $default = $column['default'];
  176. if (is_null($default) && $notnull) {
  177. $default = '';
  178. }
  179. }
  180. $autoincrement = false;
  181. if (!empty($column['autoincrement'])) {
  182. $autoincrement = true;
  183. }
  184. $definition[0] = array(
  185. 'notnull' => $notnull,
  186. 'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type'])
  187. );
  188. if (!is_null($length)) {
  189. $definition[0]['length'] = $length;
  190. }
  191. if (!is_null($unsigned)) {
  192. $definition[0]['unsigned'] = $unsigned;
  193. }
  194. if (!is_null($fixed)) {
  195. $definition[0]['fixed'] = $fixed;
  196. }
  197. if ($default !== false) {
  198. $definition[0]['default'] = $default;
  199. }
  200. if ($autoincrement !== false) {
  201. $definition[0]['autoincrement'] = $autoincrement;
  202. }
  203. foreach ($types as $key => $type) {
  204. $definition[$key] = $definition[0];
  205. if ($type == 'clob' || $type == 'blob') {
  206. unset($definition[$key]['default']);
  207. }
  208. $definition[$key]['type'] = $type;
  209. $definition[$key]['mdb2type'] = $type;
  210. }
  211. return $definition;
  212. }
  213. }
  214. return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
  215. 'it was not specified an existing table column', __FUNCTION__);
  216. }
  217. // }}}
  218. // {{{ getTableIndexDefinition()
  219. /**
  220. * Get the stucture of an index into an array
  221. *
  222. * @param string $table_name name of table that should be used in method
  223. * @param string $index_name name of index that should be used in method
  224. * @return mixed data array on success, a MDB2 error on failure
  225. * @access public
  226. */
  227. function getTableIndexDefinition($table_name, $index_name)
  228. {
  229. $db =$this->getDBInstance();
  230. if (PEAR::isError($db)) {
  231. return $db;
  232. }
  233. list($schema, $table) = $this->splitTableSchema($table_name);
  234. $query = "SELECT sql FROM sqlite_master WHERE type='index' AND ";
  235. if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
  236. $query.= 'LOWER(name)=%s AND LOWER(tbl_name)=' . $db->quote(strtolower($table), 'text');
  237. } else {
  238. $query.= 'name=%s AND tbl_name=' . $db->quote($table, 'text');
  239. }
  240. $query.= ' AND sql NOT NULL ORDER BY name';
  241. $index_name_mdb2 = $db->getIndexName($index_name);
  242. if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
  243. $qry = sprintf($query, $db->quote(strtolower($index_name_mdb2), 'text'));
  244. } else {
  245. $qry = sprintf($query, $db->quote($index_name_mdb2, 'text'));
  246. }
  247. $sql = $db->queryOne($qry, 'text');
  248. if (PEAR::isError($sql) || empty($sql)) {
  249. // fallback to the given $index_name, without transformation
  250. if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
  251. $qry = sprintf($query, $db->quote(strtolower($index_name), 'text'));
  252. } else {
  253. $qry = sprintf($query, $db->quote($index_name, 'text'));
  254. }
  255. $sql = $db->queryOne($qry, 'text');
  256. }
  257. if (PEAR::isError($sql)) {
  258. return $sql;
  259. }
  260. if (!$sql) {
  261. return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
  262. 'it was not specified an existing table index', __FUNCTION__);
  263. }
  264. $sql = strtolower($sql);
  265. $start_pos = strpos($sql, '(');
  266. $end_pos = strrpos($sql, ')');
  267. $column_names = substr($sql, $start_pos+1, $end_pos-$start_pos-1);
  268. $column_names = explode(',', $column_names);
  269. if (preg_match("/^create unique/", $sql)) {
  270. return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
  271. 'it was not specified an existing table index', __FUNCTION__);
  272. }
  273. $definition = array();
  274. $count = count($column_names);
  275. for ($i=0; $i<$count; ++$i) {
  276. $column_name = strtok($column_names[$i], ' ');
  277. $collation = strtok(' ');
  278. $definition['fields'][$column_name] = array(
  279. 'position' => $i+1
  280. );
  281. if (!empty($collation)) {
  282. $definition['fields'][$column_name]['sorting'] =
  283. ($collation=='ASC' ? 'ascending' : 'descending');
  284. }
  285. }
  286. if (empty($definition['fields'])) {
  287. return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
  288. 'it was not specified an existing table index', __FUNCTION__);
  289. }
  290. return $definition;
  291. }
  292. // }}}
  293. // {{{ getTableConstraintDefinition()
  294. /**
  295. * Get the stucture of a constraint into an array
  296. *
  297. * @param string $table_name name of table that should be used in method
  298. * @param string $constraint_name name of constraint that should be used in method
  299. * @return mixed data array on success, a MDB2 error on failure
  300. * @access public
  301. */
  302. function getTableConstraintDefinition($table_name, $constraint_name)
  303. {
  304. $db =$this->getDBInstance();
  305. if (PEAR::isError($db)) {
  306. return $db;
  307. }
  308. list($schema, $table) = $this->splitTableSchema($table_name);
  309. $query = "SELECT sql FROM sqlite_master WHERE type='index' AND ";
  310. if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
  311. $query.= 'LOWER(name)=%s AND LOWER(tbl_name)=' . $db->quote(strtolower($table), 'text');
  312. } else {
  313. $query.= 'name=%s AND tbl_name=' . $db->quote($table, 'text');
  314. }
  315. $query.= ' AND sql NOT NULL ORDER BY name';
  316. $constraint_name_mdb2 = $db->getIndexName($constraint_name);
  317. if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
  318. $qry = sprintf($query, $db->quote(strtolower($constraint_name_mdb2), 'text'));
  319. } else {
  320. $qry = sprintf($query, $db->quote($constraint_name_mdb2, 'text'));
  321. }
  322. $sql = $db->queryOne($qry, 'text');
  323. if (PEAR::isError($sql) || empty($sql)) {
  324. // fallback to the given $index_name, without transformation
  325. if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
  326. $qry = sprintf($query, $db->quote(strtolower($constraint_name), 'text'));
  327. } else {
  328. $qry = sprintf($query, $db->quote($constraint_name, 'text'));
  329. }
  330. $sql = $db->queryOne($qry, 'text');
  331. }
  332. if (PEAR::isError($sql)) {
  333. return $sql;
  334. }
  335. //default values, eventually overridden
  336. $definition = array(
  337. 'primary' => false,
  338. 'unique' => false,
  339. 'foreign' => false,
  340. 'check' => false,
  341. 'fields' => array(),
  342. 'references' => array(
  343. 'table' => '',
  344. 'fields' => array(),
  345. ),
  346. 'onupdate' => '',
  347. 'ondelete' => '',
  348. 'match' => '',
  349. 'deferrable' => false,
  350. 'initiallydeferred' => false,
  351. );
  352. if (!$sql) {
  353. $query = "SELECT sql FROM sqlite_master WHERE type='table' AND ";
  354. if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
  355. $query.= 'LOWER(name)='.$db->quote(strtolower($table), 'text');
  356. } else {
  357. $query.= 'name='.$db->quote($table, 'text');
  358. }
  359. $query.= " AND sql NOT NULL ORDER BY name";
  360. $sql = $db->queryOne($query, 'text');
  361. if (PEAR::isError($sql)) {
  362. return $sql;
  363. }
  364. if ($constraint_name == 'primary') {
  365. // search in table definition for PRIMARY KEYs
  366. if (preg_match("/\bPRIMARY\s+KEY\b\s*\(([^)]+)/i", $sql, $tmp)) {
  367. $definition['primary'] = true;
  368. $definition['fields'] = array();
  369. $column_names = explode(',', $tmp[1]);
  370. $colpos = 1;
  371. foreach ($column_names as $column_name) {
  372. $definition['fields'][trim($column_name)] = array(
  373. 'position' => $colpos++
  374. );
  375. }
  376. return $definition;
  377. }
  378. if (preg_match("/\"([^\"]+)\"[^\,\"]+\bPRIMARY\s+KEY\b[^\,\)]*/i", $sql, $tmp)) {
  379. $definition['primary'] = true;
  380. $definition['fields'] = array();
  381. $column_names = explode(',', $tmp[1]);
  382. $colpos = 1;
  383. foreach ($column_names as $column_name) {
  384. $definition['fields'][trim($column_name)] = array(
  385. 'position' => $colpos++
  386. );
  387. }
  388. return $definition;
  389. }
  390. } else {
  391. // search in table definition for FOREIGN KEYs
  392. $pattern = "/\bCONSTRAINT\b\s+%s\s+
  393. \bFOREIGN\s+KEY\b\s*\(([^\)]+)\)\s*
  394. \bREFERENCES\b\s+([^\s]+)\s*\(([^\)]+)\)\s*
  395. (?:\bMATCH\s*([^\s]+))?\s*
  396. (?:\bON\s+UPDATE\s+([^\s,\)]+))?\s*
  397. (?:\bON\s+DELETE\s+([^\s,\)]+))?\s*
  398. /imsx";
  399. $found_fk = false;
  400. if (preg_match(sprintf($pattern, $constraint_name_mdb2), $sql, $tmp)) {
  401. $found_fk = true;
  402. } elseif (preg_match(sprintf($pattern, $constraint_name), $sql, $tmp)) {
  403. $found_fk = true;
  404. }
  405. if ($found_fk) {
  406. $definition['foreign'] = true;
  407. $definition['match'] = 'SIMPLE';
  408. $definition['onupdate'] = 'NO ACTION';
  409. $definition['ondelete'] = 'NO ACTION';
  410. $definition['references']['table'] = $tmp[2];
  411. $column_names = explode(',', $tmp[1]);
  412. $colpos = 1;
  413. foreach ($column_names as $column_name) {
  414. $definition['fields'][trim($column_name)] = array(
  415. 'position' => $colpos++
  416. );
  417. }
  418. $referenced_cols = explode(',', $tmp[3]);
  419. $colpos = 1;
  420. foreach ($referenced_cols as $column_name) {
  421. $definition['references']['fields'][trim($column_name)] = array(
  422. 'position' => $colpos++
  423. );
  424. }
  425. if (isset($tmp[4])) {
  426. $definition['match'] = $tmp[4];
  427. }
  428. if (isset($tmp[5])) {
  429. $definition['onupdate'] = $tmp[5];
  430. }
  431. if (isset($tmp[6])) {
  432. $definition['ondelete'] = $tmp[6];
  433. }
  434. return $definition;
  435. }
  436. }
  437. $sql = false;
  438. }
  439. if (!$sql) {
  440. return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
  441. $constraint_name . ' is not an existing table constraint', __FUNCTION__);
  442. }
  443. $sql = strtolower($sql);
  444. $start_pos = strpos($sql, '(');
  445. $end_pos = strrpos($sql, ')');
  446. $column_names = substr($sql, $start_pos+1, $end_pos-$start_pos-1);
  447. $column_names = explode(',', $column_names);
  448. if (!preg_match("/^create unique/", $sql)) {
  449. return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
  450. $constraint_name . ' is not an existing table constraint', __FUNCTION__);
  451. }
  452. $definition['unique'] = true;
  453. $count = count($column_names);
  454. for ($i=0; $i<$count; ++$i) {
  455. $column_name = strtok($column_names[$i]," ");
  456. $collation = strtok(" ");
  457. $definition['fields'][$column_name] = array(
  458. 'position' => $i+1
  459. );
  460. if (!empty($collation)) {
  461. $definition['fields'][$column_name]['sorting'] =
  462. ($collation=='ASC' ? 'ascending' : 'descending');
  463. }
  464. }
  465. if (empty($definition['fields'])) {
  466. return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
  467. $constraint_name . ' is not an existing table constraint', __FUNCTION__);
  468. }
  469. return $definition;
  470. }
  471. // }}}
  472. // {{{ getTriggerDefinition()
  473. /**
  474. * Get the structure of a trigger into an array
  475. *
  476. * EXPERIMENTAL
  477. *
  478. * WARNING: this function is experimental and may change the returned value
  479. * at any time until labelled as non-experimental
  480. *
  481. * @param string $trigger name of trigger that should be used in method
  482. * @return mixed data array on success, a MDB2 error on failure
  483. * @access public
  484. */
  485. function getTriggerDefinition($trigger)
  486. {
  487. $db =$this->getDBInstance();
  488. if (PEAR::isError($db)) {
  489. return $db;
  490. }
  491. $query = "SELECT name as trigger_name,
  492. tbl_name AS table_name,
  493. sql AS trigger_body,
  494. NULL AS trigger_type,
  495. NULL AS trigger_event,
  496. NULL AS trigger_comment,
  497. 1 AS trigger_enabled
  498. FROM sqlite_master
  499. WHERE type='trigger'";
  500. if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
  501. $query.= ' AND LOWER(name)='.$db->quote(strtolower($trigger), 'text');
  502. } else {
  503. $query.= ' AND name='.$db->quote($trigger, 'text');
  504. }
  505. $types = array(
  506. 'trigger_name' => 'text',
  507. 'table_name' => 'text',
  508. 'trigger_body' => 'text',
  509. 'trigger_type' => 'text',
  510. 'trigger_event' => 'text',
  511. 'trigger_comment' => 'text',
  512. 'trigger_enabled' => 'boolean',
  513. );
  514. $def = $db->queryRow($query, $types, MDB2_FETCHMODE_ASSOC);
  515. if (PEAR::isError($def)) {
  516. return $def;
  517. }
  518. if (empty($def)) {
  519. return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
  520. 'it was not specified an existing trigger', __FUNCTION__);
  521. }
  522. if (preg_match("/^create\s+(?:temp|temporary)?trigger\s+(?:if\s+not\s+exists\s+)?.*(before|after)?\s+(insert|update|delete)/Uims", $def['trigger_body'], $tmp)) {
  523. $def['trigger_type'] = strtoupper($tmp[1]);
  524. $def['trigger_event'] = strtoupper($tmp[2]);
  525. }
  526. return $def;
  527. }
  528. // }}}
  529. // {{{ tableInfo()
  530. /**
  531. * Returns information about a table
  532. *
  533. * @param string $result a string containing the name of a table
  534. * @param int $mode a valid tableInfo mode
  535. *
  536. * @return array an associative array with the information requested.
  537. * A MDB2_Error object on failure.
  538. *
  539. * @see MDB2_Driver_Common::tableInfo()
  540. * @since Method available since Release 1.7.0
  541. */
  542. function tableInfo($result, $mode = null)
  543. {
  544. if (is_string($result)) {
  545. return parent::tableInfo($result, $mode);
  546. }
  547. $db =$this->getDBInstance();
  548. if (PEAR::isError($db)) {
  549. return $db;
  550. }
  551. return $db->raiseError(MDB2_ERROR_NOT_CAPABLE, null, null,
  552. 'This DBMS can not obtain tableInfo from result sets', __FUNCTION__);
  553. }
  554. }