odbc.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. <?php
  2. require_once 'MDB2/Driver/Reverse/Common.php';
  3. /**
  4. * MDB2 MSSQL driver for the schema reverse engineering module
  5. *
  6. * @package MDB2
  7. * @category Database
  8. * @author Lukas Smith <smith@dybnet.de>
  9. * @author Lorenzo Alberton <l.alberton@quipo.it>
  10. */
  11. class MDB2_Driver_Reverse_odbc extends MDB2_Driver_Reverse_Common
  12. {
  13. // {{{ getTableFieldDefinition()
  14. /**
  15. * Get the structure of a field into an array
  16. *
  17. * @param string $table_name name of table that should be used in method
  18. * @param string $field_name name of field that should be used in method
  19. * @return mixed data array on success, a MDB2 error on failure
  20. * @access public
  21. */
  22. function getTableFieldDefinition($table_name, $field_name)
  23. {
  24. $db =& $this->getDBInstance();
  25. if (MDB2::isError($db)) {
  26. return $db;
  27. }
  28. $result = $db->loadModule('Datatype', null, true);
  29. if (MDB2::isError($result)) {
  30. return $result;
  31. }
  32. list($schema, $table) = $this->splitTableSchema($table_name);
  33. $table = $db->quoteIdentifier($table, true);
  34. $fldname = $db->quoteIdentifier($field_name, true);
  35. $res = odbc_columns($db->connection,"%","%",$table);
  36. $column = array();
  37. while($data = odbc_fetch_array($res)) {
  38. if(strcasecmp($field_name,$data['COLUMN_NAME'])) {
  39. $column['table_name'] = $data['TABLE_NAME'];
  40. $column['name'] = $data['COLUMN_NAME'];
  41. $column['type'] = $data['TYPE_NAME'];
  42. if($data['IS_NULLABLE'] == "YES") {
  43. $column['is_nullable'] = 1;
  44. } else {
  45. $column['is_nullable'] = 0;
  46. }
  47. $column['column_default'] = $data['COLUMN_DEF'];
  48. $column['length'] = $data['COLUMNZ_SIZE'];
  49. $column['numeric_precision'] = $data['NUM_PREC_RADIX'];
  50. $column['numeric_scale'] = $data['DECIMAL_DIGITS'];
  51. $column['collation_name'] = NULL;
  52. }
  53. }
  54. /*
  55. $query = "SELECT t.table_name,
  56. c.column_name 'name',
  57. c.data_type 'type',
  58. CASE c.is_nullable WHEN 'YES' THEN 1 ELSE 0 END AS 'is_nullable',
  59. c.column_default,
  60. c.character_maximum_length 'length',
  61. c.numeric_precision,
  62. c.numeric_scale,
  63. c.character_set_name,
  64. c.collation_name
  65. FROM INFORMATION_SCHEMA.TABLES t,
  66. INFORMATION_SCHEMA.COLUMNS c
  67. WHERE t.table_name = c.table_name
  68. AND t.table_name = '$table'
  69. AND c.column_name = '$fldname'";
  70. if (!empty($schema)) {
  71. $query .= " AND t.table_schema = '" .$db->quoteIdentifier($schema, true) ."'";
  72. }
  73. $query .= ' ORDER BY t.table_name';
  74. $column = $db->queryRow($query, null, MDB2_FETCHMODE_ASSOC);
  75. if (MDB2::isError($column)) {
  76. return $column;
  77. }
  78. */
  79. if (empty($column)) {
  80. return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
  81. 'it was not specified an existing table column', __FUNCTION__);
  82. }
  83. if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
  84. if ($db->options['field_case'] == CASE_LOWER) {
  85. $column['name'] = strtolower($column['name']);
  86. } else {
  87. $column['name'] = strtoupper($column['name']);
  88. }
  89. } else {
  90. $column = array_change_key_case($column, $db->options['field_case']);
  91. }
  92. $mapped_datatype = $db->datatype->mapNativeDatatype($column);
  93. if (MDB2::isError($mapped_datatype)) {
  94. return $mapped_datatype;
  95. }
  96. list($types, $length, $unsigned, $fixed) = $mapped_datatype;
  97. $notnull = true;
  98. if ($column['is_nullable']) {
  99. $notnull = false;
  100. }
  101. $default = false;
  102. if (array_key_exists('column_default', $column)) {
  103. $default = $column['column_default'];
  104. if (is_null($default) && $notnull) {
  105. $default = '';
  106. } elseif (strlen($default) > 4
  107. && substr($default, 0, 1) == '('
  108. && substr($default, -1, 1) == ')'
  109. ) {
  110. //mssql wraps the default value in parentheses: "((1234))", "(NULL)"
  111. $default = trim($default, '()');
  112. if ($default == 'NULL') {
  113. $default = null;
  114. }
  115. }
  116. }
  117. $definition[0] = array(
  118. 'notnull' => $notnull,
  119. 'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type'])
  120. );
  121. if (!is_null($length)) {
  122. $definition[0]['length'] = $length;
  123. }
  124. if (!is_null($unsigned)) {
  125. $definition[0]['unsigned'] = $unsigned;
  126. }
  127. if (!is_null($fixed)) {
  128. $definition[0]['fixed'] = $fixed;
  129. }
  130. if ($default !== false) {
  131. $definition[0]['default'] = $default;
  132. }
  133. foreach ($types as $key => $type) {
  134. $definition[$key] = $definition[0];
  135. if ($type == 'clob' || $type == 'blob') {
  136. unset($definition[$key]['default']);
  137. }
  138. $definition[$key]['type'] = $type;
  139. $definition[$key]['mdb2type'] = $type;
  140. }
  141. return $definition;
  142. }
  143. // }}}
  144. // {{{ getTableIndexDefinition()
  145. /**
  146. * Get the structure of an index into an array
  147. *
  148. * @param string $table_name name of table that should be used in method
  149. * @param string $index_name name of index that should be used in method
  150. * @return mixed data array on success, a MDB2 error on failure
  151. * @access public
  152. */
  153. function getTableIndexDefinition($table_name, $index_name)
  154. {
  155. $db =& $this->getDBInstance();
  156. if (MDB2::isError($db)) {
  157. return $db;
  158. }
  159. list($schema, $table) = $this->splitTableSchema($table_name);
  160. $table = $db->quoteIdentifier($table, true);
  161. //$idxname = $db->quoteIdentifier($index_name, true);
  162. $query = "SELECT OBJECT_NAME(i.id) tablename,
  163. i.name indexname,
  164. c.name field_name,
  165. CASE INDEXKEY_PROPERTY(i.id, i.indid, ik.keyno, 'IsDescending')
  166. WHEN 1 THEN 'DESC' ELSE 'ASC'
  167. END 'collation',
  168. ik.keyno 'position'
  169. FROM sysindexes i
  170. JOIN sysindexkeys ik ON ik.id = i.id AND ik.indid = i.indid
  171. JOIN syscolumns c ON c.id = ik.id AND c.colid = ik.colid
  172. WHERE OBJECT_NAME(i.id) = '$table'
  173. AND i.name = '%s'
  174. AND NOT EXISTS (
  175. SELECT *
  176. FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE k
  177. WHERE k.table_name = OBJECT_NAME(i.id)
  178. AND k.constraint_name = i.name";
  179. if (!empty($schema)) {
  180. $query .= " AND k.table_schema = '" .$db->quoteIdentifier($schema, true) ."'";
  181. }
  182. $query .= ')
  183. ORDER BY tablename, indexname, ik.keyno';
  184. $index_name_mdb2 = $db->getIndexName($index_name);
  185. $result = $db->queryRow(sprintf($query, $index_name_mdb2));
  186. if (!MDB2::isError($result) && !is_null($result)) {
  187. // apply 'idxname_format' only if the query succeeded, otherwise
  188. // fallback to the given $index_name, without transformation
  189. $index_name = $index_name_mdb2;
  190. }
  191. $result = $db->query(sprintf($query, $index_name));
  192. if (MDB2::isError($result)) {
  193. return $result;
  194. }
  195. $definition = array();
  196. while (is_array($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))) {
  197. $column_name = $row['field_name'];
  198. if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
  199. if ($db->options['field_case'] == CASE_LOWER) {
  200. $column_name = strtolower($column_name);
  201. } else {
  202. $column_name = strtoupper($column_name);
  203. }
  204. }
  205. $definition['fields'][$column_name] = array(
  206. 'position' => (int)$row['position'],
  207. );
  208. if (!empty($row['collation'])) {
  209. $definition['fields'][$column_name]['sorting'] = ($row['collation'] == 'ASC'
  210. ? 'ascending' : 'descending');
  211. }
  212. }
  213. $result->free();
  214. if (empty($definition['fields'])) {
  215. return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
  216. 'it was not specified an existing table index', __FUNCTION__);
  217. }
  218. return $definition;
  219. }
  220. // }}}
  221. // {{{ getTableConstraintDefinition()
  222. /**
  223. * Get the structure of a constraint into an array
  224. *
  225. * @param string $table_name name of table that should be used in method
  226. * @param string $constraint_name name of constraint that should be used in method
  227. * @return mixed data array on success, a MDB2 error on failure
  228. * @access public
  229. */
  230. function getTableConstraintDefinition($table_name, $constraint_name)
  231. {
  232. $db =& $this->getDBInstance();
  233. if (MDB2::isError($db)) {
  234. return $db;
  235. }
  236. list($schema, $table) = $this->splitTableSchema($table_name);
  237. $table = $db->quoteIdentifier($table, true);
  238. $query = "SELECT k.table_name,
  239. k.column_name field_name,
  240. CASE c.constraint_type WHEN 'PRIMARY KEY' THEN 1 ELSE 0 END 'primary',
  241. CASE c.constraint_type WHEN 'UNIQUE' THEN 1 ELSE 0 END 'unique',
  242. CASE c.constraint_type WHEN 'FOREIGN KEY' THEN 1 ELSE 0 END 'foreign',
  243. CASE c.constraint_type WHEN 'CHECK' THEN 1 ELSE 0 END 'check',
  244. CASE c.is_deferrable WHEN 'NO' THEN 0 ELSE 1 END 'deferrable',
  245. CASE c.initially_deferred WHEN 'NO' THEN 0 ELSE 1 END 'initiallydeferred',
  246. rc.match_option 'match',
  247. rc.update_rule 'onupdate',
  248. rc.delete_rule 'ondelete',
  249. kcu.table_name 'references_table',
  250. kcu.column_name 'references_field',
  251. k.ordinal_position 'field_position'
  252. FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE k
  253. LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS c
  254. ON k.table_name = c.table_name
  255. AND k.table_schema = c.table_schema
  256. AND k.table_catalog = c.table_catalog
  257. AND k.constraint_catalog = c.constraint_catalog
  258. AND k.constraint_name = c.constraint_name
  259. LEFT JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc
  260. ON rc.constraint_schema = c.constraint_schema
  261. AND rc.constraint_catalog = c.constraint_catalog
  262. AND rc.constraint_name = c.constraint_name
  263. LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu
  264. ON rc.unique_constraint_schema = kcu.constraint_schema
  265. AND rc.unique_constraint_catalog = kcu.constraint_catalog
  266. AND rc.unique_constraint_name = kcu.constraint_name
  267. AND k.ordinal_position = kcu.ordinal_position
  268. WHERE k.constraint_catalog = DB_NAME()
  269. AND k.table_name = '$table'
  270. AND k.constraint_name = '%s'";
  271. if (!empty($schema)) {
  272. $query .= " AND k.table_schema = '" .$db->quoteIdentifier($schema, true) ."'";
  273. }
  274. $query .= ' ORDER BY k.constraint_name,
  275. k.ordinal_position';
  276. $constraint_name_mdb2 = $db->getIndexName($constraint_name);
  277. $result = $db->queryRow(sprintf($query, $constraint_name_mdb2));
  278. if (!MDB2::isError($result) && !is_null($result)) {
  279. // apply 'idxname_format' only if the query succeeded, otherwise
  280. // fallback to the given $index_name, without transformation
  281. $constraint_name = $constraint_name_mdb2;
  282. }
  283. $result = $db->query(sprintf($query, $constraint_name));
  284. if (MDB2::isError($result)) {
  285. return $result;
  286. }
  287. $definition = array(
  288. 'fields' => array()
  289. );
  290. while (is_array($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))) {
  291. $row = array_change_key_case($row, CASE_LOWER);
  292. $column_name = $row['field_name'];
  293. if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
  294. if ($db->options['field_case'] == CASE_LOWER) {
  295. $column_name = strtolower($column_name);
  296. } else {
  297. $column_name = strtoupper($column_name);
  298. }
  299. }
  300. $definition['fields'][$column_name] = array(
  301. 'position' => (int)$row['field_position']
  302. );
  303. if ($row['foreign']) {
  304. $ref_column_name = $row['references_field'];
  305. if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
  306. if ($db->options['field_case'] == CASE_LOWER) {
  307. $ref_column_name = strtolower($ref_column_name);
  308. } else {
  309. $ref_column_name = strtoupper($ref_column_name);
  310. }
  311. }
  312. $definition['references']['table'] = $row['references_table'];
  313. $definition['references']['fields'][$ref_column_name] = array(
  314. 'position' => (int)$row['field_position']
  315. );
  316. }
  317. //collation?!?
  318. /*
  319. if (!empty($row['collation'])) {
  320. $definition['fields'][$column_name]['sorting'] = ($row['collation'] == 'ASC'
  321. ? 'ascending' : 'descending');
  322. }
  323. */
  324. $lastrow = $row;
  325. // otherwise $row is no longer usable on exit from loop
  326. }
  327. $result->free();
  328. if (empty($definition['fields'])) {
  329. return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
  330. $constraint_name . ' is not an existing table constraint', __FUNCTION__);
  331. }
  332. $definition['primary'] = (boolean)$lastrow['primary'];
  333. $definition['unique'] = (boolean)$lastrow['unique'];
  334. $definition['foreign'] = (boolean)$lastrow['foreign'];
  335. $definition['check'] = (boolean)$lastrow['check'];
  336. $definition['deferrable'] = (boolean)$lastrow['deferrable'];
  337. $definition['initiallydeferred'] = (boolean)$lastrow['initiallydeferred'];
  338. $definition['onupdate'] = $lastrow['onupdate'];
  339. $definition['ondelete'] = $lastrow['ondelete'];
  340. $definition['match'] = $lastrow['match'];
  341. return $definition;
  342. }
  343. // }}}
  344. // {{{ getTriggerDefinition()
  345. /**
  346. * Get the structure of a trigger into an array
  347. *
  348. * EXPERIMENTAL
  349. *
  350. * WARNING: this function is experimental and may change the returned value
  351. * at any time until labelled as non-experimental
  352. *
  353. * @param string $trigger name of trigger that should be used in method
  354. * @return mixed data array on success, a MDB2 error on failure
  355. * @access public
  356. */
  357. function getTriggerDefinition($trigger)
  358. {
  359. $db =& $this->getDBInstance();
  360. if (MDB2::isError($db)) {
  361. return $db;
  362. }
  363. $query = "SELECT sys1.name trigger_name,
  364. sys2.name table_name,
  365. c.text trigger_body,
  366. c.encrypted is_encripted,
  367. CASE
  368. WHEN OBJECTPROPERTY(sys1.id, 'ExecIsTriggerDisabled') = 1
  369. THEN 0 ELSE 1
  370. END trigger_enabled,
  371. CASE
  372. WHEN OBJECTPROPERTY(sys1.id, 'ExecIsInsertTrigger') = 1
  373. THEN 'INSERT'
  374. WHEN OBJECTPROPERTY(sys1.id, 'ExecIsUpdateTrigger') = 1
  375. THEN 'UPDATE'
  376. WHEN OBJECTPROPERTY(sys1.id, 'ExecIsDeleteTrigger') = 1
  377. THEN 'DELETE'
  378. END trigger_event,
  379. CASE WHEN OBJECTPROPERTY(sys1.id, 'ExecIsInsteadOfTrigger') = 1
  380. THEN 'INSTEAD OF' ELSE 'AFTER'
  381. END trigger_type,
  382. '' trigger_comment
  383. FROM sysobjects sys1
  384. JOIN sysobjects sys2 ON sys1.parent_obj = sys2.id
  385. JOIN syscomments c ON sys1.id = c.id
  386. WHERE sys1.xtype = 'TR'
  387. AND sys1.name = ". $db->quote($trigger, 'text');
  388. $types = array(
  389. 'trigger_name' => 'text',
  390. 'table_name' => 'text',
  391. 'trigger_body' => 'text',
  392. 'trigger_type' => 'text',
  393. 'trigger_event' => 'text',
  394. 'trigger_comment' => 'text',
  395. 'trigger_enabled' => 'boolean',
  396. 'is_encripted' => 'boolean',
  397. );
  398. $def = $db->queryRow($query, $types, MDB2_FETCHMODE_ASSOC);
  399. if (MDB2::isError($def)) {
  400. return $def;
  401. }
  402. $trg_body = $db->queryCol('EXEC sp_helptext '. $db->quote($trigger, 'text'), 'text');
  403. if (!MDB2::isError($trg_body)) {
  404. $def['trigger_body'] = implode(' ', $trg_body);
  405. }
  406. return $def;
  407. }
  408. // }}}
  409. // {{{ tableInfo()
  410. /**
  411. * Returns information about a table or a result set
  412. *
  413. * NOTE: only supports 'table' and 'flags' if <var>$result</var>
  414. * is a table name.
  415. *
  416. * @param object|string $result MDB2_result object from a query or a
  417. * string containing the name of a table.
  418. * While this also accepts a query result
  419. * resource identifier, this behavior is
  420. * deprecated.
  421. * @param int $mode a valid tableInfo mode
  422. *
  423. * @return array an associative array with the information requested.
  424. * A MDB2_Error object on failure.
  425. *
  426. * @see MDB2_Driver_Common::tableInfo()
  427. */
  428. function tableInfo($result, $mode = null)
  429. {
  430. if (is_string($result)) {
  431. return parent::tableInfo($result, $mode);
  432. }
  433. $db =& $this->getDBInstance();
  434. if (MDB2::isError($db)) {
  435. return $db;
  436. }
  437. $resource = MDB2::isResultCommon($result) ? $result->getResource() : $result;
  438. if (!is_resource($resource)) {
  439. return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
  440. 'Could not generate result resource', __FUNCTION__);
  441. }
  442. if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
  443. if ($db->options['field_case'] == CASE_LOWER) {
  444. $case_func = 'strtolower';
  445. } else {
  446. $case_func = 'strtoupper';
  447. }
  448. } else {
  449. $case_func = 'strval';
  450. }
  451. $count = @mssql_num_fields($resource);
  452. $res = array();
  453. if ($mode) {
  454. $res['num_fields'] = $count;
  455. }
  456. $db->loadModule('Datatype', null, true);
  457. for ($i = 0; $i < $count; $i++) {
  458. $res[$i] = array(
  459. 'table' => '',
  460. 'name' => $case_func(@mssql_field_name($resource, $i)),
  461. 'type' => @mssql_field_type($resource, $i),
  462. 'length' => @mssql_field_length($resource, $i),
  463. 'flags' => '',
  464. );
  465. $mdb2type_info = $db->datatype->mapNativeDatatype($res[$i]);
  466. if (MDB2::isError($mdb2type_info)) {
  467. return $mdb2type_info;
  468. }
  469. $res[$i]['mdb2type'] = $mdb2type_info[0][0];
  470. if ($mode & MDB2_TABLEINFO_ORDER) {
  471. $res['order'][$res[$i]['name']] = $i;
  472. }
  473. if ($mode & MDB2_TABLEINFO_ORDERTABLE) {
  474. $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
  475. }
  476. }
  477. return $res;
  478. }
  479. // }}}
  480. // {{{ _mssql_field_flags()
  481. /**
  482. * Get a column's flags
  483. *
  484. * Supports "not_null", "primary_key",
  485. * "auto_increment" (mssql identity), "timestamp" (mssql timestamp),
  486. * "unique_key" (mssql unique index, unique check or primary_key) and
  487. * "multiple_key" (multikey index)
  488. *
  489. * mssql timestamp is NOT similar to the mysql timestamp so this is maybe
  490. * not useful at all - is the behaviour of mysql_field_flags that primary
  491. * keys are alway unique? is the interpretation of multiple_key correct?
  492. *
  493. * @param string $table the table name
  494. * @param string $column the field name
  495. *
  496. * @return string the flags
  497. *
  498. * @access protected
  499. * @author Joern Barthel <j_barthel@web.de>
  500. */
  501. function _mssql_field_flags($table, $column)
  502. {
  503. $db =& $this->getDBInstance();
  504. if (MDB2::isError($db)) {
  505. return $db;
  506. }
  507. static $tableName = null;
  508. static $flags = array();
  509. if ($table != $tableName) {
  510. $flags = array();
  511. $tableName = $table;
  512. // get unique and primary keys
  513. $res = $db->queryAll("EXEC SP_HELPINDEX[$table]", null, MDB2_FETCHMODE_ASSOC);
  514. foreach ($res as $val) {
  515. $val = array_change_key_case($val, CASE_LOWER);
  516. $keys = explode(', ', $val['index_keys']);
  517. if (sizeof($keys) > 1) {
  518. foreach ($keys as $key) {
  519. $this->_add_flag($flags[$key], 'multiple_key');
  520. }
  521. }
  522. if (strpos($val['index_description'], 'primary key')) {
  523. foreach ($keys as $key) {
  524. $this->_add_flag($flags[$key], 'primary_key');
  525. }
  526. } elseif (strpos($val['index_description'], 'unique')) {
  527. foreach ($keys as $key) {
  528. $this->_add_flag($flags[$key], 'unique_key');
  529. }
  530. }
  531. }
  532. // get auto_increment, not_null and timestamp
  533. $res = $db->queryAll("EXEC SP_COLUMNS[$table]", null, MDB2_FETCHMODE_ASSOC);
  534. foreach ($res as $val) {
  535. $val = array_change_key_case($val, CASE_LOWER);
  536. if ($val['nullable'] == '0') {
  537. $this->_add_flag($flags[$val['column_name']], 'not_null');
  538. }
  539. if (strpos($val['type_name'], 'identity')) {
  540. $this->_add_flag($flags[$val['column_name']], 'auto_increment');
  541. }
  542. if (strpos($val['type_name'], 'timestamp')) {
  543. $this->_add_flag($flags[$val['column_name']], 'timestamp');
  544. }
  545. }
  546. }
  547. if (!empty($flags[$column])) {
  548. return(implode(' ', $flags[$column]));
  549. }
  550. return '';
  551. }
  552. // }}}
  553. // {{{ _add_flag()
  554. /**
  555. * Adds a string to the flags array if the flag is not yet in there
  556. * - if there is no flag present the array is created
  557. *
  558. * @param array &$array the reference to the flag-array
  559. * @param string $value the flag value
  560. *
  561. * @return void
  562. *
  563. * @access protected
  564. * @author Joern Barthel <j_barthel@web.de>
  565. */
  566. function _add_flag(&$array, $value)
  567. {
  568. if (!is_array($array)) {
  569. $array = array($value);
  570. } elseif (!in_array($value, $array)) {
  571. array_push($array, $value);
  572. }
  573. }
  574. // }}}
  575. }
  576. ?>