datadict-sybase.inc.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. /**
  3. V4.60 24 Jan 2005 (c) 2000-2005 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. // security - hide paths
  10. if (!defined('ADODB_DIR')) die();
  11. class ADODB2_sybase extends ADODB_DataDict {
  12. var $databaseType = 'sybase';
  13. var $dropIndex = 'DROP INDEX %2$s.%1$s';
  14. function MetaType($t,$len=-1,$fieldobj=false)
  15. {
  16. if (is_object($t)) {
  17. $fieldobj = $t;
  18. $t = $fieldobj->type;
  19. $len = $fieldobj->max_length;
  20. }
  21. $len = -1; // mysql max_length is not accurate
  22. switch (strtoupper($t)) {
  23. case 'INT':
  24. case 'INTEGER': return 'I';
  25. case 'BIT':
  26. case 'TINYINT': return 'I1';
  27. case 'SMALLINT': return 'I2';
  28. case 'BIGINT': return 'I8';
  29. case 'REAL':
  30. case 'FLOAT': return 'F';
  31. default: return parent::MetaType($t,$len,$fieldobj);
  32. }
  33. }
  34. function ActualType($meta)
  35. {
  36. switch(strtoupper($meta)) {
  37. case 'C': return 'VARCHAR';
  38. case 'XL':
  39. case 'X': return 'TEXT';
  40. case 'C2': return 'NVARCHAR';
  41. case 'X2': return 'NTEXT';
  42. case 'B': return 'IMAGE';
  43. case 'D': return 'DATETIME';
  44. case 'T': return 'DATETIME';
  45. case 'L': return 'BIT';
  46. case 'I': return 'INT';
  47. case 'I1': return 'TINYINT';
  48. case 'I2': return 'SMALLINT';
  49. case 'I4': return 'INT';
  50. case 'I8': return 'BIGINT';
  51. case 'F': return 'REAL';
  52. case 'N': return 'NUMERIC';
  53. default:
  54. return $meta;
  55. }
  56. }
  57. function AddColumnSQL($tabname, $flds)
  58. {
  59. $tabname = $this->TableName ($tabname);
  60. $f = array();
  61. list($lines,$pkey) = $this->_GenFields($flds);
  62. $s = "ALTER TABLE $tabname $this->addCol";
  63. foreach($lines as $v) {
  64. $f[] = "\n $v";
  65. }
  66. $s .= implode(', ',$f);
  67. $sql[] = $s;
  68. return $sql;
  69. }
  70. function AlterColumnSQL($tabname, $flds)
  71. {
  72. $tabname = $this->TableName ($tabname);
  73. $sql = array();
  74. list($lines,$pkey) = $this->_GenFields($flds);
  75. foreach($lines as $v) {
  76. $sql[] = "ALTER TABLE $tabname $this->alterCol $v";
  77. }
  78. return $sql;
  79. }
  80. function DropColumnSQL($tabname, $flds)
  81. {
  82. $tabname = $this->TableName($tabname);
  83. if (!is_array($flds)) $flds = explode(',',$flds);
  84. $f = array();
  85. $s = "ALTER TABLE $tabname";
  86. foreach($flds as $v) {
  87. $f[] = "\n$this->dropCol ".$this->NameQuote($v);
  88. }
  89. $s .= implode(', ',$f);
  90. $sql[] = $s;
  91. return $sql;
  92. }
  93. // return string must begin with space
  94. function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint)
  95. {
  96. $suffix = '';
  97. if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
  98. if ($fautoinc) $suffix .= ' DEFAULT AUTOINCREMENT';
  99. if ($fnotnull) $suffix .= ' NOT NULL';
  100. else if ($suffix == '') $suffix .= ' NULL';
  101. if ($fconstraint) $suffix .= ' '.$fconstraint;
  102. return $suffix;
  103. }
  104. /*
  105. CREATE TABLE
  106. [ database_name.[ owner ] . | owner. ] table_name
  107. ( { < column_definition >
  108. | column_name AS computed_column_expression
  109. | < table_constraint > ::= [ CONSTRAINT constraint_name ] }
  110. | [ { PRIMARY KEY | UNIQUE } [ ,...n ]
  111. )
  112. [ ON { filegroup | DEFAULT } ]
  113. [ TEXTIMAGE_ON { filegroup | DEFAULT } ]
  114. < column_definition > ::= { column_name data_type }
  115. [ COLLATE < collation_name > ]
  116. [ [ DEFAULT constant_expression ]
  117. | [ IDENTITY [ ( seed , increment ) [ NOT FOR REPLICATION ] ] ]
  118. ]
  119. [ ROWGUIDCOL]
  120. [ < column_constraint > ] [ ...n ]
  121. < column_constraint > ::= [ CONSTRAINT constraint_name ]
  122. { [ NULL | NOT NULL ]
  123. | [ { PRIMARY KEY | UNIQUE }
  124. [ CLUSTERED | NONCLUSTERED ]
  125. [ WITH FILLFACTOR = fillfactor ]
  126. [ON {filegroup | DEFAULT} ] ]
  127. ]
  128. | [ [ FOREIGN KEY ]
  129. REFERENCES ref_table [ ( ref_column ) ]
  130. [ ON DELETE { CASCADE | NO ACTION } ]
  131. [ ON UPDATE { CASCADE | NO ACTION } ]
  132. [ NOT FOR REPLICATION ]
  133. ]
  134. | CHECK [ NOT FOR REPLICATION ]
  135. ( logical_expression )
  136. }
  137. < table_constraint > ::= [ CONSTRAINT constraint_name ]
  138. { [ { PRIMARY KEY | UNIQUE }
  139. [ CLUSTERED | NONCLUSTERED ]
  140. { ( column [ ASC | DESC ] [ ,...n ] ) }
  141. [ WITH FILLFACTOR = fillfactor ]
  142. [ ON { filegroup | DEFAULT } ]
  143. ]
  144. | FOREIGN KEY
  145. [ ( column [ ,...n ] ) ]
  146. REFERENCES ref_table [ ( ref_column [ ,...n ] ) ]
  147. [ ON DELETE { CASCADE | NO ACTION } ]
  148. [ ON UPDATE { CASCADE | NO ACTION } ]
  149. [ NOT FOR REPLICATION ]
  150. | CHECK [ NOT FOR REPLICATION ]
  151. ( search_conditions )
  152. }
  153. */
  154. /*
  155. CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name
  156. ON { table | view } ( column [ ASC | DESC ] [ ,...n ] )
  157. [ WITH < index_option > [ ,...n] ]
  158. [ ON filegroup ]
  159. < index_option > :: =
  160. { PAD_INDEX |
  161. FILLFACTOR = fillfactor |
  162. IGNORE_DUP_KEY |
  163. DROP_EXISTING |
  164. STATISTICS_NORECOMPUTE |
  165. SORT_IN_TEMPDB
  166. }
  167. */
  168. function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
  169. {
  170. $sql = array();
  171. if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
  172. $sql[] = sprintf ($this->dropIndex, $idxname, $tabname);
  173. if ( isset($idxoptions['DROP']) )
  174. return $sql;
  175. }
  176. if ( empty ($flds) ) {
  177. return $sql;
  178. }
  179. $unique = isset($idxoptions['UNIQUE']) ? ' UNIQUE' : '';
  180. $clustered = isset($idxoptions['CLUSTERED']) ? ' CLUSTERED' : '';
  181. if ( is_array($flds) )
  182. $flds = implode(', ',$flds);
  183. $s = 'CREATE' . $unique . $clustered . ' INDEX ' . $idxname . ' ON ' . $tabname . ' (' . $flds . ')';
  184. if ( isset($idxoptions[$this->upperName]) )
  185. $s .= $idxoptions[$this->upperName];
  186. $sql[] = $s;
  187. return $sql;
  188. }
  189. }
  190. ?>