Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
DALDb2Converter.inc
1 <?php
13 require_once dirname(__FILE__).'/DALConverter.inc';
14 
26 {
27 
34  protected $name = 'DB2';
35 
42  protected $dataTypes = array(
43  'char' => 'CHAR',
44  'varchar' => 'VARCHAR',
45  'clob' => 'CLOB',
46  'blob' => 'BLOB',
47  'integer' => 'INT',
48  'smallint' => 'SMALLINT',
49  'numeric' => 'NUMERIC',
50  'float' => 'FLOAT',
51  'real' => 'REAL',
52  'double_precision' => 'DOUBLE PRECISION',
53  'boolean' => 'CHAR',
54  'date' => 'DATE',
55  'time' => 'TIME',
56  'timestamp' => 'TIMESTAMP',
57  'time with time zone' => 'TIME',
58  );
59 
60 
66  public function __construct()
67  {
68 
69  }//end __construct()
70 
71 
82  protected function handleFunctionSeqNextVal($seqName)
83  {
84  $sql = 'SELECT next value for '.$seqName[0].' FROM SYSIBM.SYSDUMMY1';
85  return $sql;
86 
87  }//end handleFunctionSeqNextVal()
88 
89 
100  protected function handleFunctionSeqCurrVal($seqName)
101  {
102  $sql = 'SELECT prevval for '.$seqName[0].' FROM SYSIBM.SYSDUMMY1';
103  return $sql;
104 
105  }//end handleFunctionSeqCurrVal()
106 
107 
116  public function handleFunctionTableExists($tableName)
117  {
118  if (is_array($tableName) === TRUE) {
119  $tableName = $tableName[0];
120  }
121 
122  $sql = 'SELECT count(*) FROM syscat.tables WHERE tabname = UPPER(CAST('.$tableName.' AS VARCHAR(50)))';
123  return $sql;
124 
125  }//end handleFunctionTableExists()
126 
127 
136  public function handleFunctionSequenceExists($sequenceName)
137  {
138  if (is_array($sequenceName) === TRUE) {
139  $sequenceName = $sequenceName[0];
140  }
141 
142  $sql = 'SELECT count(*) FROM syscat.sequences WHERE seqname = '.$sequenceName;
143  return $sql;
144 
145  }//end handleFunctionSequenceExists()
146 
147 
159  protected function handleFunctionToDate(array $args)
160  {
161  $iso8601_date = $this->convertSingleField($args[0]);
162 
163  // DB2 appears to allow casting by calling the data type as a function.
164  $sql = 'TIMESTAMP('.$iso8601_date.')';
165  return $sql;
166 
167  }//end handleFunctionToDate()
168 
169 
178  protected function getUnionType(array $union)
179  {
180  $type = '';
181  if (isset($union['UNION']) === TRUE) {
182  $type = 'UNION';
183  } else if (isset($union['UNION-ALL']) === TRUE) {
184  $type = 'UNION-ALL';
185  }
186 
187  return $type;
188 
189  }//end getUnionType()
190 
191 
200  protected function convertUnionDisplayName($type)
201  {
202  if ($type === 'UNION-ALL') {
203  return 'UNION ALL';
204  }
205 
206  return $type;
207 
208  }//end convertUnionDisplayName()
209 
210 
219  protected function handleFunctionConcat(array $args)
220  {
221  $sql = implode(' || ', $args);
222  return $sql;
223 
224  }//end handleFunctionConcat()
225 
226 
235  protected function convertLikeCondition(array $condition)
236  {
237  $compare = $this->convertSingleField($condition['compare']);
238  $to = $this->convertSingleField($condition['to']);
239  $sql = 'LOCATE('.str_replace('%', '', $to).', '.str_replace('%', '', $compare).') <> 0';
240 
241  return $sql;
242 
243  }//end convertLikeCondition()
244 
245 
258  protected function handleFunctionBindcast(array $args)
259  {
260  $sql = $this->handleFunctionCast($args);
261  return $sql;
262 
263  }//end handleFunctionBindcast()
264 
265 
276  protected function handleFunctionSubstring(array $args)
277  {
278  // SUBSTRING(input FROM start-position [FOR length])
279  if (count($args) != 2 && count($args) != 3) {
280  $msg = 'The SUBSTR() function only accepts two or three parameters.';
281  throw new DALConverterException($msg);
282  }
283 
284  $input = $this->convertSingleField($args[0]);
285  $start = $args[1];
286  $length = isset($args[2]) ? ",$args[2]" : '';
287  $sql = "SUBSTRING($input, $start $length, OCTETS)";
288 
289  return $sql;
290 
291  }//end handleFunctionSubstring()
292 
293 
294 }//end class
295 ?>