Subversion Repositories PHPX

Rev

Rev 29 | Rev 33 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 29 Rev 32
Line 19... Line 19...
19
 *   Last success value of the database operation
19
 *   Last success value of the database operation
20
 * @author Thomas Lahn
20
 * @author Thomas Lahn
21
 */
21
 */
22
class Database extends AbstractModel
22
class Database extends AbstractModel
23
{
23
{
-
 
24
  /* Access properties */
-
 
25
 
24
  /**
26
  /**
25
   * DSN of the database
27
   * DSN of the database
26
   * @var string
28
   * @var string
27
   */
29
   */
28
  protected $_dsn = '';
30
  protected $_dsn = '';
Line 42... Line 44...
42
  /**
44
  /**
43
   * PDO driver-specific options
45
   * PDO driver-specific options
44
   * @var array
46
   * @var array
45
   */
47
   */
46
  protected $_options = array();
48
  protected $_options = array();
-
 
49
-
 
50
  /**
-
 
51
   * Database-specific string to use for quoting a name or value
-
 
52
   * left-hand side (for security reasons and to prevent a name
-
 
53
   * from being parsed as a keyword).
-
 
54
   * @var string
-
 
55
   */
-
 
56
  protected $_leftQuote = '';
-
 
57
 
-
 
58
  /**
-
 
59
   * Database-specific string to use for quoting a name or value
-
 
60
   * left-hand side (for security reasons and to prevent a name
-
 
61
   * from being parsed as a keyword).
-
 
62
   * @var string
-
 
63
   */
-
 
64
  protected $_rightQuote = '';
-
 
65
 
-
 
66
  /* Status properties */
47
 
67
 
48
  /**
68
  /**
49
   * Database connection
69
   * Database connection
50
   * @var PDO
70
   * @var PDO
51
   */
71
   */
Line 143... Line 163...
143
   * @return string
163
   * @return string
144
   *   The escaped name
164
   *   The escaped name
145
   */
165
   */
146
  public function escapeName($name)
166
  public function escapeName($name)
147
  {
167
  {
148
    return $name;
168
    return $this->_leftQuote . $name . $this->_rightQuote;
149
  }
169
  }
150
 
170
 
151
  /**
171
  /**
152
   * Determines if an array is associative (has not all integer keys).
172
   * Determines if an array is associative (has not all integer keys).
153
   *
173
   *
Line 181... Line 201...
181
   */
201
   */
182
  protected function _escapeAliasArray(array &$array)
202
  protected function _escapeAliasArray(array &$array)
183
  {
203
  {
184
    foreach ($array as $column => &$value)
204
    foreach ($array as $column => &$value)
185
    {
205
    {
-
 
206
      $quotedColumn = $column;
-
 
207
      if (strpos($column, $this->_leftQuote) === false
-
 
208
         && strpos($column, $this->_rightQuote) === false)
-
 
209
      {
-
 
210
        $quotedColumn = $this->_leftQuote . $column . $this->_rightQuote;
-
 
211
      }
-
 
212
     
186
      $value = $value . ' AS ' . $column;
213
      $value = $value . ' AS ' . $quotedColumn;
187
    }
214
    }
188
 
215
 
189
    return $array;
216
    return $array;
190
  }
217
  }
191
218
Line 226... Line 253...
226
   *   The strings to use left-hand side (index 0) and right-hand side (index 1)
253
   *   The strings to use left-hand side (index 0) and right-hand side (index 1)
227
   *   of the column name.  The default is the empty string, respectively.
254
   *   of the column name.  The default is the empty string, respectively.
228
   * @return array
255
   * @return array
229
   *   The escaped array
256
   *   The escaped array
230
   */
257
   */
231
  protected function _escapeValueArray(array &$array, $suffix = '', array &$escape = array('', ''))
258
  protected function _escapeValueArray(array &$array, $suffix = '')
232
  {
259
  {
233
    $result = array();
260
    $result = array();
234
       
261
       
235
    foreach ($array as $column => $value)
262
    foreach ($array as $column => $value)
236
    {
263
    {
Line 248... Line 275...
248
      if (is_array($value))
275
      if (is_array($value))
249
      {
276
      {
250
        $placeholder = '(' . implode(',', self::_expand($value, $column)) . ')';
277
        $placeholder = '(' . implode(',', self::_expand($value, $column)) . ')';
251
      }
278
      }
252
     
279
     
253
      $result[] = $escape[0] . $column . $escape[1] . "{$op}{$placeholder}{$suffix}";
280
      $result[] = $this->_leftQuote . $column . $this->_rightQuote . "{$op}{$placeholder}{$suffix}";
254
    }
281
    }
255
 
282
 
256
    return $result;
283
    return $result;
257
  }
284
  }
258
   
285