Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/*
3
 *  $Id: Mock.php 7490 2010-03-29 19:53:27Z jwage $
4
 *
5
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16
 *
17
 * This software consists of voluntary contributions made by many individuals
18
 * and is licensed under the LGPL. For more information, see
19
 * <http://www.doctrine-project.org>.
20
 */
21
 
22
/**
23
 * Mock connection adapter statement class. Used for special testing purposes
24
 *
25
 * @package     Doctrine
26
 * @subpackage  Adapter
27
 * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
28
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
29
 * @link        www.doctrine-project.org
30
 * @since       1.0
31
 * @version     $Revision: 7490 $
32
 */
33
class Doctrine_Adapter_Statement_Mock implements Doctrine_Adapter_Statement_Interface
34
{
35
    /**
36
     * Variable which stores instance of Doctrine_Adapter_Mock
37
     *
38
     * @var Doctrine_Adapter_Mock
39
     */
40
    private $_mock;
41
 
42
    /**
43
     * queryString
44
     *
45
     * @var string
46
     */
47
    public $queryString;
48
 
49
    /**
50
     * Constructor for mock adapter statements. Accepts instance of Doctrine_Adapter_Mock
51
     *
52
     * @param Doctrine_Adapter_Mock $mock
53
     */
54
    public function __construct($mock)
55
    {
56
        $this->_mock  = $mock;
57
    }
58
 
59
    /**
60
     * bindColumn
61
     *
62
     * Bind a column to a PHP variable
63
     *
64
     * @param mixed $column         Number of the column (1-indexed) or name of the column in the result set.
65
     *                              If using the column name, be aware that the name should match
66
     *                              the case of the column, as returned by the driver.
67
     * @param string $param         Name of the PHP variable to which the column will be bound.
68
     * @param integer $type         Data type of the parameter, specified by the Doctrine_Core::PARAM_* constants.
69
     * @return boolean              Returns TRUE on success or FALSE on failure
70
     */
71
    public function bindColumn($column, $param, $type = null)
72
    { }
73
 
74
    /**
75
     * bindValue
76
     *
77
     * Binds a value to a corresponding named or question mark
78
     * placeholder in the SQL statement that was use to prepare the statement.
79
     *
80
     * @param mixed $param          Parameter identifier. For a prepared statement using named placeholders,
81
     *                              this will be a parameter name of the form :name. For a prepared statement
82
     *                              using question mark placeholders, this will be the 1-indexed position of the parameter
83
     *
84
     * @param mixed $value          The value to bind to the parameter.
85
     * @param integer $type         Explicit data type for the parameter using the Doctrine_Core::PARAM_* constants.
86
     *
87
     * @return boolean              Returns TRUE on success or FALSE on failure.
88
     */
89
    public function bindValue($param, $value, $type = null)
90
    { }
91
 
92
    /**
93
     * bindParam
94
     *
95
     * Binds a PHP variable to a corresponding named or question mark placeholder in the
96
     * SQL statement that was use to prepare the statement. Unlike Doctrine_Adapter_Statement_Interface->bindValue(),
97
     * the variable is bound as a reference and will only be evaluated at the time
98
     * that Doctrine_Adapter_Statement_Interface->execute() is called.
99
     *
100
     * Most parameters are input parameters, that is, parameters that are
101
     * used in a read-only fashion to build up the query. Some drivers support the invocation
102
     * of stored procedures that return data as output parameters, and some also as input/output
103
     * parameters that both send in data and are updated to receive it.
104
     *
105
     * @param mixed $param          Parameter identifier. For a prepared statement using named placeholders,
106
     *                              this will be a parameter name of the form :name. For a prepared statement
107
     *                              using question mark placeholders, this will be the 1-indexed position of the parameter
108
     *
109
     * @param mixed $variable       Name of the PHP variable to bind to the SQL statement parameter.
110
     *
111
     * @param integer $type         Explicit data type for the parameter using the Doctrine_Core::PARAM_* constants. To return
112
     *                              an INOUT parameter from a stored procedure, use the bitwise OR operator to set the
113
     *                              Doctrine_Core::PARAM_INPUT_OUTPUT bits for the data_type parameter.
114
     *
115
     * @param integer $length       Length of the data type. To indicate that a parameter is an OUT parameter
116
     *                              from a stored procedure, you must explicitly set the length.
117
     * @param mixed $driverOptions
118
     * @return boolean              Returns TRUE on success or FALSE on failure.
119
     */
120
    public function bindParam($column, &$variable, $type = null, $length = null, $driverOptions = array())
121
    {
122
 
123
    }
124
 
125
    /**
126
     * closeCursor
127
     *
128
     * Closes the cursor, enabling the statement to be executed again.
129
     *
130
     * @return boolean              Returns TRUE on success or FALSE on failure.
131
     */
132
    public function closeCursor()
133
    {
134
        return true;
135
    }
136
 
137
    /**
138
     * columnCount
139
     *
140
     * Returns the number of columns in the result set
141
     *
142
     * @return integer              Returns the number of columns in the result set represented
143
     *                              by the Doctrine_Adapter_Statement_Interface object. If there is no result set,
144
     *                              this method should return 0.
145
     */
146
    public function columnCount()
147
    {
148
        return 0;
149
    }
150
 
151
    /**
152
     * errorCode
153
     *
154
     * Fetch the SQLSTATE associated with the last operation on the statement handle
155
     *
156
     * @see Doctrine_Adapter_Interface::errorCode()
157
     * @return string       error code string
158
     */
159
    public function errorCode()
160
    {
161
        return array();
162
    }
163
 
164
    /**
165
     * errorInfo
166
     *
167
     * Fetch extended error information associated with the last operation on the statement handle
168
     *
169
     * @see Doctrine_Adapter_Interface::errorInfo()
170
     * @return array        error info array
171
     */
172
    public function errorInfo()
173
    {
174
        return array();
175
    }
176
 
177
    /**
178
     * fetch
179
     *
180
     * @see Doctrine_Core::FETCH_* constants
181
     * @param integer $fetchStyle           Controls how the next row will be returned to the caller.
182
     *                                      This value must be one of the Doctrine_Core::FETCH_* constants,
183
     *                                      defaulting to Doctrine_Core::FETCH_BOTH
184
     *
185
     * @param integer $cursorOrientation    For a PDOStatement object representing a scrollable cursor,
186
     *                                      this value determines which row will be returned to the caller.
187
     *                                      This value must be one of the Doctrine_Core::FETCH_ORI_* constants, defaulting to
188
     *                                      Doctrine_Core::FETCH_ORI_NEXT. To request a scrollable cursor for your
189
     *                                      Doctrine_Adapter_Statement_Interface object,
190
     *                                      you must set the Doctrine_Core::ATTR_CURSOR attribute to Doctrine_Core::CURSOR_SCROLL when you
191
     *                                      prepare the SQL statement with Doctrine_Adapter_Interface->prepare().
192
     *
193
     * @param integer $cursorOffset         For a Doctrine_Adapter_Statement_Interface object representing a scrollable cursor for which the
194
     *                                      $cursorOrientation parameter is set to Doctrine_Core::FETCH_ORI_ABS, this value specifies
195
     *                                      the absolute number of the row in the result set that shall be fetched.
196
     *
197
     *                                      For a Doctrine_Adapter_Statement_Interface object representing a scrollable cursor for
198
     *                                      which the $cursorOrientation parameter is set to Doctrine_Core::FETCH_ORI_REL, this value
199
     *                                      specifies the row to fetch relative to the cursor position before
200
     *                                      Doctrine_Adapter_Statement_Interface->fetch() was called.
201
     *
202
     * @return mixed
203
     */
204
    public function fetch($fetchStyle = Doctrine_Core::FETCH_BOTH,
205
                          $cursorOrientation = Doctrine_Core::FETCH_ORI_NEXT,
206
                          $cursorOffset = null)
207
    {
208
        return array();
209
    }
210
 
211
    /**
212
     * fetchAll
213
     *
214
     * Returns an array containing all of the result set rows
215
     *
216
     * @param integer $fetchStyle           Controls how the next row will be returned to the caller.
217
     *                                      This value must be one of the Doctrine_Core::FETCH_* constants,
218
     *                                      defaulting to Doctrine_Core::FETCH_BOTH
219
     *
220
     * @param integer $columnIndex          Returns the indicated 0-indexed column when the value of $fetchStyle is
221
     *                                      Doctrine_Core::FETCH_COLUMN. Defaults to 0.
222
     *
223
     * @return array
224
     */
225
    public function fetchAll($fetchMode = Doctrine_Core::FETCH_BOTH)
226
    {
227
        return array();
228
    }
229
 
230
    /**
231
     * execute
232
     *
233
     * Executes a prepared statement
234
     *
235
     * If the prepared statement included parameter markers, you must either:
236
     * call PDOStatement->bindParam() to bind PHP variables to the parameter markers:
237
     * bound variables pass their value as input and receive the output value,
238
     * if any, of their associated parameter markers or pass an array of input-only
239
     * parameter values
240
     *
241
     *
242
     * @param array $params             An array of values with as many elements as there are
243
     *                                  bound parameters in the SQL statement being executed.
244
     * @return boolean                  Returns TRUE on success or FALSE on failure.
245
     */
246
    public function execute($params = null)
247
    {
248
        if (is_object($this->_mock)) {
249
            $this->_mock->addQuery($this->queryString);
250
        }
251
        return true;
252
    }
253
 
254
    /**
255
     * fetchColumn
256
     *
257
     * Returns a single column from the next row of a
258
     * result set or FALSE if there are no more rows.
259
     *
260
     * @param integer $columnIndex          0-indexed number of the column you wish to retrieve from the row. If no
261
     *                                      value is supplied, Doctrine_Adapter_Statement_Interface->fetchColumn()
262
     *                                      fetches the first column.
263
     *
264
     * @return string                       returns a single column in the next row of a result set.
265
     */
266
    public function fetchColumn($columnIndex = 0)
267
    {
268
        return 0;
269
    }
270
 
271
    /**
272
     * fetchObject
273
     *
274
     * Fetches the next row and returns it as an object.
275
     *
276
     * Fetches the next row and returns it as an object. This function is an alternative to
277
     * Doctrine_Adapter_Statement_Interface->fetch() with Doctrine_Core::FETCH_CLASS or Doctrine_Core::FETCH_OBJ style.
278
     *
279
     * @param string $className             Name of the created class, defaults to stdClass.
280
     * @param array $args                   Elements of this array are passed to the constructor.
281
     *
282
     * @return mixed                        an instance of the required class with property names that correspond
283
     *                                      to the column names or FALSE in case of an error.
284
     */
285
    public function fetchObject($className = 'stdClass', $args = array())
286
    {
287
        return new $className();
288
    }
289
 
290
    /**
291
     * nextRowset
292
     *
293
     * Advances to the next rowset in a multi-rowset statement handle
294
     *
295
     * Some database servers support stored procedures that return more than one rowset
296
     * (also known as a result set). The nextRowset() method enables you to access the second
297
     * and subsequent rowsets associated with a PDOStatement object. Each rowset can have a
298
     * different set of columns from the preceding rowset.
299
     *
300
     * @return boolean                      Returns TRUE on success or FALSE on failure.
301
     */
302
    public function nextRowset()
303
    {
304
        return true;
305
    }
306
 
307
    /**
308
     * rowCount
309
     *
310
     * rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement
311
     * executed by the corresponding object.
312
     *
313
     * If the last SQL statement executed by the associated Statement object was a SELECT statement,
314
     * some databases may return the number of rows returned by that statement. However,
315
     * this behaviour is not guaranteed for all databases and should not be
316
     * relied on for portable applications.
317
     *
318
     * @return integer                      Returns the number of rows.
319
     */
320
    public function rowCount()
321
    {
322
        return 0;
323
    }
324
 
325
    /**
326
     * getColumnMeta
327
     *
328
     * Returns metadata for a column in a result set
329
     *
330
     * @param integer $column               The 0-indexed column in the result set.
331
     *
332
     * @return array                        Associative meta data array with the following structure:
333
     *
334
     *          native_type                 The PHP native type used to represent the column value.
335
     *          driver:decl_                type The SQL type used to represent the column value in the database. If the column in the result set is the result of a function, this value is not returned by PDOStatement->getColumnMeta().
336
     *          flags                       Any flags set for this column.
337
     *          name                        The name of this column as returned by the database.
338
     *          len                         The length of this column. Normally -1 for types other than floating point decimals.
339
     *          precision                   The numeric precision of this column. Normally 0 for types other than floating point decimals.
340
     *          pdo_type                    The type of this column as represented by the PDO::PARAM_* constants.
341
     */
342
    public function getColumnMeta($column)
343
    { }
344
 
345
    /**
346
     * getAttribute
347
     *
348
     * Retrieve a statement attribute
349
     *
350
     * @param integer $attribute
351
     * @see Doctrine_Core::ATTR_* constants
352
     * @return mixed                        the attribute value
353
     */
354
    public function getAttribute($attribute)
355
    { }
356
 
357
    /**
358
     * setAttribute
359
     *
360
     * Set a statement attribute
361
     *
362
     * @param integer $attribute
363
     * @param mixed $value                  the value of given attribute
364
     * @return boolean                      Returns TRUE on success or FALSE on failure.
365
     */
366
    public function setAttribute($attribute, $value)
367
    { }
368
 
369
    /**
370
     * setFetchMode
371
     *
372
     * Set the default fetch mode for this statement
373
     *
374
     * @param integer $mode                 The fetch mode must be one of the Doctrine_Core::FETCH_* constants.
375
     * @return boolean                      Returns 1 on success or FALSE on failure.
376
     */
377
    public function setFetchMode($mode, $arg1 = null, $arg2 = null)
378
    { }
379
}