Subversion Repositories Applications.papyrus

Rev

Rev 320 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 320 Rev 443
1
<?php
1
<?php
2
 
2
 
3
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
 
4
 
5
/**
5
/**
6
 * The PEAR DB driver for PHP's ifx extension
6
 * The PEAR DB driver for PHP's ifx extension
7
 * for interacting with Informix databases
7
 * for interacting with Informix databases
8
 *
8
 *
9
 * PHP versions 4 and 5
9
 * PHP versions 4 and 5
10
 *
10
 *
11
 * LICENSE: This source file is subject to version 3.0 of the PHP license
11
 * LICENSE: This source file is subject to version 3.0 of the PHP license
12
 * that is available through the world-wide-web at the following URI:
12
 * that is available through the world-wide-web at the following URI:
13
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
13
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
14
 * the PHP License and are unable to obtain it through the web, please
14
 * the PHP License and are unable to obtain it through the web, please
15
 * send a note to license@php.net so we can mail you a copy immediately.
15
 * send a note to license@php.net so we can mail you a copy immediately.
16
 *
16
 *
17
 * @category   Database
17
 * @category   Database
18
 * @package    DB
18
 * @package    DB
19
 * @author     Tomas V.V.Cox <cox@idecnet.com>
19
 * @author     Tomas V.V.Cox <cox@idecnet.com>
20
 * @author     Daniel Convissor <danielc@php.net>
20
 * @author     Daniel Convissor <danielc@php.net>
21
 * @copyright  1997-2005 The PHP Group
21
 * @copyright  1997-2005 The PHP Group
22
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
22
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
23
 * @version    CVS: $Id: ifx.php,v 1.1 2005-03-30 08:50:33 jpm Exp $
23
 * @version    CVS: $Id: ifx.php,v 1.2 2005-09-20 17:01:22 ddelon Exp $
24
 * @link       http://pear.php.net/package/DB
24
 * @link       http://pear.php.net/package/DB
25
 */
25
 */
26
 
26
 
27
/**
27
/**
28
 * Obtain the DB_common class so it can be extended from
28
 * Obtain the DB_common class so it can be extended from
29
 */
29
 */
30
require_once 'DB/common.php';
30
require_once 'DB/common.php';
31
 
31
 
32
/**
32
/**
33
 * The methods PEAR DB uses to interact with PHP's ifx extension
33
 * The methods PEAR DB uses to interact with PHP's ifx extension
34
 * for interacting with Informix databases
34
 * for interacting with Informix databases
35
 *
35
 *
36
 * These methods overload the ones declared in DB_common.
36
 * These methods overload the ones declared in DB_common.
37
 *
37
 *
38
 * More info on Informix errors can be found at:
38
 * More info on Informix errors can be found at:
39
 * http://www.informix.com/answers/english/ierrors.htm
39
 * http://www.informix.com/answers/english/ierrors.htm
40
 *
40
 *
41
 * TODO:
41
 * TODO:
42
 *   - set needed env Informix vars on connect
42
 *   - set needed env Informix vars on connect
43
 *   - implement native prepare/execute
43
 *   - implement native prepare/execute
44
 *
44
 *
45
 * @category   Database
45
 * @category   Database
46
 * @package    DB
46
 * @package    DB
47
 * @author     Tomas V.V.Cox <cox@idecnet.com>
47
 * @author     Tomas V.V.Cox <cox@idecnet.com>
48
 * @author     Daniel Convissor <danielc@php.net>
48
 * @author     Daniel Convissor <danielc@php.net>
49
 * @copyright  1997-2005 The PHP Group
49
 * @copyright  1997-2005 The PHP Group
50
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
50
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
51
 * @version    Release: 1.7.5
51
 * @version    Release: @package_version@
52
 * @link       http://pear.php.net/package/DB
52
 * @link       http://pear.php.net/package/DB
53
 */
53
 */
54
class DB_ifx extends DB_common
54
class DB_ifx extends DB_common
55
{
55
{
56
    // {{{ properties
56
    // {{{ properties
57
 
57
 
58
    /**
58
    /**
59
     * The DB driver type (mysql, oci8, odbc, etc.)
59
     * The DB driver type (mysql, oci8, odbc, etc.)
60
     * @var string
60
     * @var string
61
     */
61
     */
62
    var $phptype = 'ifx';
62
    var $phptype = 'ifx';
63
 
63
 
64
    /**
64
    /**
65
     * The database syntax variant to be used (db2, access, etc.), if any
65
     * The database syntax variant to be used (db2, access, etc.), if any
66
     * @var string
66
     * @var string
67
     */
67
     */
68
    var $dbsyntax = 'ifx';
68
    var $dbsyntax = 'ifx';
69
 
69
 
70
    /**
70
    /**
71
     * The capabilities of this DB implementation
71
     * The capabilities of this DB implementation
72
     *
72
     *
73
     * The 'new_link' element contains the PHP version that first provided
73
     * The 'new_link' element contains the PHP version that first provided
74
     * new_link support for this DBMS.  Contains false if it's unsupported.
74
     * new_link support for this DBMS.  Contains false if it's unsupported.
75
     *
75
     *
76
     * Meaning of the 'limit' element:
76
     * Meaning of the 'limit' element:
77
     *   + 'emulate' = emulate with fetch row by number
77
     *   + 'emulate' = emulate with fetch row by number
78
     *   + 'alter'   = alter the query
78
     *   + 'alter'   = alter the query
79
     *   + false     = skip rows
79
     *   + false     = skip rows
80
     *
80
     *
81
     * @var array
81
     * @var array
82
     */
82
     */
83
    var $features = array(
83
    var $features = array(
84
        'limit'         => 'emulate',
84
        'limit'         => 'emulate',
85
        'new_link'      => false,
85
        'new_link'      => false,
86
        'numrows'       => 'emulate',
86
        'numrows'       => 'emulate',
87
        'pconnect'      => true,
87
        'pconnect'      => true,
88
        'prepare'       => false,
88
        'prepare'       => false,
89
        'ssl'           => false,
89
        'ssl'           => false,
90
        'transactions'  => true,
90
        'transactions'  => true,
91
    );
91
    );
92
 
92
 
93
    /**
93
    /**
94
     * A mapping of native error codes to DB error codes
94
     * A mapping of native error codes to DB error codes
95
     * @var array
95
     * @var array
96
     */
96
     */
97
    var $errorcode_map = array(
97
    var $errorcode_map = array(
98
        '-201'    => DB_ERROR_SYNTAX,
98
        '-201'    => DB_ERROR_SYNTAX,
99
        '-206'    => DB_ERROR_NOSUCHTABLE,
99
        '-206'    => DB_ERROR_NOSUCHTABLE,
100
        '-217'    => DB_ERROR_NOSUCHFIELD,
100
        '-217'    => DB_ERROR_NOSUCHFIELD,
101
        '-236'    => DB_ERROR_VALUE_COUNT_ON_ROW,
101
        '-236'    => DB_ERROR_VALUE_COUNT_ON_ROW,
102
        '-239'    => DB_ERROR_CONSTRAINT,
102
        '-239'    => DB_ERROR_CONSTRAINT,
103
        '-253'    => DB_ERROR_SYNTAX,
103
        '-253'    => DB_ERROR_SYNTAX,
104
        '-292'    => DB_ERROR_CONSTRAINT_NOT_NULL,
104
        '-292'    => DB_ERROR_CONSTRAINT_NOT_NULL,
105
        '-310'    => DB_ERROR_ALREADY_EXISTS,
105
        '-310'    => DB_ERROR_ALREADY_EXISTS,
106
        '-316'    => DB_ERROR_ALREADY_EXISTS,
106
        '-316'    => DB_ERROR_ALREADY_EXISTS,
107
        '-319'    => DB_ERROR_NOT_FOUND,
107
        '-319'    => DB_ERROR_NOT_FOUND,
108
        '-329'    => DB_ERROR_NODBSELECTED,
108
        '-329'    => DB_ERROR_NODBSELECTED,
109
        '-346'    => DB_ERROR_CONSTRAINT,
109
        '-346'    => DB_ERROR_CONSTRAINT,
110
        '-386'    => DB_ERROR_CONSTRAINT_NOT_NULL,
110
        '-386'    => DB_ERROR_CONSTRAINT_NOT_NULL,
111
        '-391'    => DB_ERROR_CONSTRAINT_NOT_NULL,
111
        '-391'    => DB_ERROR_CONSTRAINT_NOT_NULL,
112
        '-554'    => DB_ERROR_SYNTAX,
112
        '-554'    => DB_ERROR_SYNTAX,
113
        '-691'    => DB_ERROR_CONSTRAINT,
113
        '-691'    => DB_ERROR_CONSTRAINT,
114
        '-692'    => DB_ERROR_CONSTRAINT,
114
        '-692'    => DB_ERROR_CONSTRAINT,
115
        '-703'    => DB_ERROR_CONSTRAINT_NOT_NULL,
115
        '-703'    => DB_ERROR_CONSTRAINT_NOT_NULL,
116
        '-1204'   => DB_ERROR_INVALID_DATE,
116
        '-1204'   => DB_ERROR_INVALID_DATE,
117
        '-1205'   => DB_ERROR_INVALID_DATE,
117
        '-1205'   => DB_ERROR_INVALID_DATE,
118
        '-1206'   => DB_ERROR_INVALID_DATE,
118
        '-1206'   => DB_ERROR_INVALID_DATE,
119
        '-1209'   => DB_ERROR_INVALID_DATE,
119
        '-1209'   => DB_ERROR_INVALID_DATE,
120
        '-1210'   => DB_ERROR_INVALID_DATE,
120
        '-1210'   => DB_ERROR_INVALID_DATE,
121
        '-1212'   => DB_ERROR_INVALID_DATE,
121
        '-1212'   => DB_ERROR_INVALID_DATE,
122
        '-1213'   => DB_ERROR_INVALID_NUMBER,
122
        '-1213'   => DB_ERROR_INVALID_NUMBER,
123
    );
123
    );
124
 
124
 
125
    /**
125
    /**
126
     * The raw database connection created by PHP
126
     * The raw database connection created by PHP
127
     * @var resource
127
     * @var resource
128
     */
128
     */
129
    var $connection;
129
    var $connection;
130
 
130
 
131
    /**
131
    /**
132
     * The DSN information for connecting to a database
132
     * The DSN information for connecting to a database
133
     * @var array
133
     * @var array
134
     */
134
     */
135
    var $dsn = array();
135
    var $dsn = array();
136
 
136
 
137
 
137
 
138
    /**
138
    /**
139
     * Should data manipulation queries be committed automatically?
139
     * Should data manipulation queries be committed automatically?
140
     * @var bool
140
     * @var bool
141
     * @access private
141
     * @access private
142
     */
142
     */
143
    var $autocommit = true;
143
    var $autocommit = true;
144
 
144
 
145
    /**
145
    /**
146
     * The quantity of transactions begun
146
     * The quantity of transactions begun
147
     *
147
     *
148
     * {@internal  While this is private, it can't actually be designated
148
     * {@internal  While this is private, it can't actually be designated
149
     * private in PHP 5 because it is directly accessed in the test suite.}}
149
     * private in PHP 5 because it is directly accessed in the test suite.}}
150
     *
150
     *
151
     * @var integer
151
     * @var integer
152
     * @access private
152
     * @access private
153
     */
153
     */
154
    var $transaction_opcount = 0;
154
    var $transaction_opcount = 0;
155
 
155
 
156
    /**
156
    /**
157
     * The number of rows affected by a data manipulation query
157
     * The number of rows affected by a data manipulation query
158
     * @var integer
158
     * @var integer
159
     * @access private
159
     * @access private
160
     */
160
     */
161
    var $affected = 0;
161
    var $affected = 0;
162
 
162
 
163
 
163
 
164
    // }}}
164
    // }}}
165
    // {{{ constructor
165
    // {{{ constructor
166
 
166
 
167
    /**
167
    /**
168
     * This constructor calls <kbd>$this->DB_common()</kbd>
168
     * This constructor calls <kbd>$this->DB_common()</kbd>
169
     *
169
     *
170
     * @return void
170
     * @return void
171
     */
171
     */
172
    function DB_ifx()
172
    function DB_ifx()
173
    {
173
    {
174
        $this->DB_common();
174
        $this->DB_common();
175
    }
175
    }
176
 
176
 
177
    // }}}
177
    // }}}
178
    // {{{ connect()
178
    // {{{ connect()
179
 
179
 
180
    /**
180
    /**
181
     * Connect to the database server, log in and open the database
181
     * Connect to the database server, log in and open the database
182
     *
182
     *
183
     * Don't call this method directly.  Use DB::connect() instead.
183
     * Don't call this method directly.  Use DB::connect() instead.
184
     *
184
     *
185
     * @param array $dsn         the data source name
185
     * @param array $dsn         the data source name
186
     * @param bool  $persistent  should the connection be persistent?
186
     * @param bool  $persistent  should the connection be persistent?
187
     *
187
     *
188
     * @return int  DB_OK on success. A DB_Error object on failure.
188
     * @return int  DB_OK on success. A DB_Error object on failure.
189
     */
189
     */
190
    function connect($dsn, $persistent = false)
190
    function connect($dsn, $persistent = false)
191
    {
191
    {
192
        if (!PEAR::loadExtension('informix') &&
192
        if (!PEAR::loadExtension('informix') &&
193
            !PEAR::loadExtension('Informix'))
193
            !PEAR::loadExtension('Informix'))
194
        {
194
        {
195
            return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
195
            return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
196
        }
196
        }
197
 
197
 
198
        $this->dsn = $dsn;
198
        $this->dsn = $dsn;
199
        if ($dsn['dbsyntax']) {
199
        if ($dsn['dbsyntax']) {
200
            $this->dbsyntax = $dsn['dbsyntax'];
200
            $this->dbsyntax = $dsn['dbsyntax'];
201
        }
201
        }
202
 
202
 
203
        $dbhost = $dsn['hostspec'] ? '@' . $dsn['hostspec'] : '';
203
        $dbhost = $dsn['hostspec'] ? '@' . $dsn['hostspec'] : '';
204
        $dbname = $dsn['database'] ? $dsn['database'] . $dbhost : '';
204
        $dbname = $dsn['database'] ? $dsn['database'] . $dbhost : '';
205
        $user = $dsn['username'] ? $dsn['username'] : '';
205
        $user = $dsn['username'] ? $dsn['username'] : '';
206
        $pw = $dsn['password'] ? $dsn['password'] : '';
206
        $pw = $dsn['password'] ? $dsn['password'] : '';
207
 
207
 
208
        $connect_function = $persistent ? 'ifx_pconnect' : 'ifx_connect';
208
        $connect_function = $persistent ? 'ifx_pconnect' : 'ifx_connect';
209
 
209
 
210
        $this->connection = @$connect_function($dbname, $user, $pw);
210
        $this->connection = @$connect_function($dbname, $user, $pw);
211
        if (!is_resource($this->connection)) {
211
        if (!is_resource($this->connection)) {
212
            return $this->ifxRaiseError(DB_ERROR_CONNECT_FAILED);
212
            return $this->ifxRaiseError(DB_ERROR_CONNECT_FAILED);
213
        }
213
        }
214
        return DB_OK;
214
        return DB_OK;
215
    }
215
    }
216
 
216
 
217
    // }}}
217
    // }}}
218
    // {{{ disconnect()
218
    // {{{ disconnect()
219
 
219
 
220
    /**
220
    /**
221
     * Disconnects from the database server
221
     * Disconnects from the database server
222
     *
222
     *
223
     * @return bool  TRUE on success, FALSE on failure
223
     * @return bool  TRUE on success, FALSE on failure
224
     */
224
     */
225
    function disconnect()
225
    function disconnect()
226
    {
226
    {
227
        $ret = @ifx_close($this->connection);
227
        $ret = @ifx_close($this->connection);
228
        $this->connection = null;
228
        $this->connection = null;
229
        return $ret;
229
        return $ret;
230
    }
230
    }
231
 
231
 
232
    // }}}
232
    // }}}
233
    // {{{ simpleQuery()
233
    // {{{ simpleQuery()
234
 
234
 
235
    /**
235
    /**
236
     * Sends a query to the database server
236
     * Sends a query to the database server
237
     *
237
     *
238
     * @param string  the SQL query string
238
     * @param string  the SQL query string
239
     *
239
     *
240
     * @return mixed  + a PHP result resrouce for successful SELECT queries
240
     * @return mixed  + a PHP result resrouce for successful SELECT queries
241
     *                + the DB_OK constant for other successful queries
241
     *                + the DB_OK constant for other successful queries
242
     *                + a DB_Error object on failure
242
     *                + a DB_Error object on failure
243
     */
243
     */
244
    function simpleQuery($query)
244
    function simpleQuery($query)
245
    {
245
    {
246
        $ismanip = DB::isManip($query);
246
        $ismanip = DB::isManip($query);
247
        $this->last_query = $query;
247
        $this->last_query = $query;
248
        $this->affected   = null;
248
        $this->affected   = null;
249
        if (preg_match('/(SELECT)/i', $query)) {    //TESTME: Use !DB::isManip()?
249
        if (preg_match('/(SELECT)/i', $query)) {    //TESTME: Use !DB::isManip()?
250
            // the scroll is needed for fetching absolute row numbers
250
            // the scroll is needed for fetching absolute row numbers
251
            // in a select query result
251
            // in a select query result
252
            $result = @ifx_query($query, $this->connection, IFX_SCROLL);
252
            $result = @ifx_query($query, $this->connection, IFX_SCROLL);
253
        } else {
253
        } else {
254
            if (!$this->autocommit && $ismanip) {
254
            if (!$this->autocommit && $ismanip) {
255
                if ($this->transaction_opcount == 0) {
255
                if ($this->transaction_opcount == 0) {
256
                    $result = @ifx_query('BEGIN WORK', $this->connection);
256
                    $result = @ifx_query('BEGIN WORK', $this->connection);
257
                    if (!$result) {
257
                    if (!$result) {
258
                        return $this->ifxRaiseError();
258
                        return $this->ifxRaiseError();
259
                    }
259
                    }
260
                }
260
                }
261
                $this->transaction_opcount++;
261
                $this->transaction_opcount++;
262
            }
262
            }
263
            $result = @ifx_query($query, $this->connection);
263
            $result = @ifx_query($query, $this->connection);
264
        }
264
        }
265
        if (!$result) {
265
        if (!$result) {
266
            return $this->ifxRaiseError();
266
            return $this->ifxRaiseError();
267
        }
267
        }
268
        $this->affected = @ifx_affected_rows($result);
268
        $this->affected = @ifx_affected_rows($result);
269
        // Determine which queries should return data, and which
269
        // Determine which queries should return data, and which
270
        // should return an error code only.
270
        // should return an error code only.
271
        if (preg_match('/(SELECT)/i', $query)) {
271
        if (preg_match('/(SELECT)/i', $query)) {
272
            return $result;
272
            return $result;
273
        }
273
        }
274
        // XXX Testme: free results inside a transaction
274
        // XXX Testme: free results inside a transaction
275
        // may cause to stop it and commit the work?
275
        // may cause to stop it and commit the work?
276
 
276
 
277
        // Result has to be freed even with a insert or update
277
        // Result has to be freed even with a insert or update
278
        @ifx_free_result($result);
278
        @ifx_free_result($result);
279
 
279
 
280
        return DB_OK;
280
        return DB_OK;
281
    }
281
    }
282
 
282
 
283
    // }}}
283
    // }}}
284
    // {{{ nextResult()
284
    // {{{ nextResult()
285
 
285
 
286
    /**
286
    /**
287
     * Move the internal ifx result pointer to the next available result
287
     * Move the internal ifx result pointer to the next available result
288
     *
288
     *
289
     * @param a valid fbsql result resource
289
     * @param a valid fbsql result resource
290
     *
290
     *
291
     * @access public
291
     * @access public
292
     *
292
     *
293
     * @return true if a result is available otherwise return false
293
     * @return true if a result is available otherwise return false
294
     */
294
     */
295
    function nextResult($result)
295
    function nextResult($result)
296
    {
296
    {
297
        return false;
297
        return false;
298
    }
298
    }
299
 
299
 
300
    // }}}
300
    // }}}
301
    // {{{ affectedRows()
301
    // {{{ affectedRows()
302
 
302
 
303
    /**
303
    /**
304
     * Determines the number of rows affected by a data maniuplation query
304
     * Determines the number of rows affected by a data maniuplation query
305
     *
305
     *
306
     * 0 is returned for queries that don't manipulate data.
306
     * 0 is returned for queries that don't manipulate data.
307
     *
307
     *
308
     * @return int  the number of rows.  A DB_Error object on failure.
308
     * @return int  the number of rows.  A DB_Error object on failure.
309
     */
309
     */
310
    function affectedRows()
310
    function affectedRows()
311
    {
311
    {
312
        if (DB::isManip($this->last_query)) {
312
        if (DB::isManip($this->last_query)) {
313
            return $this->affected;
313
            return $this->affected;
314
        } else {
314
        } else {
315
            return 0;
315
            return 0;
316
        }
316
        }
317
    }
317
    }
318
 
318
 
319
    // }}}
319
    // }}}
320
    // {{{ fetchInto()
320
    // {{{ fetchInto()
321
 
321
 
322
    /**
322
    /**
323
     * Places a row from the result set into the given array
323
     * Places a row from the result set into the given array
324
     *
324
     *
325
     * Formating of the array and the data therein are configurable.
325
     * Formating of the array and the data therein are configurable.
326
     * See DB_result::fetchInto() for more information.
326
     * See DB_result::fetchInto() for more information.
327
     *
327
     *
328
     * This method is not meant to be called directly.  Use
328
     * This method is not meant to be called directly.  Use
329
     * DB_result::fetchInto() instead.  It can't be declared "protected"
329
     * DB_result::fetchInto() instead.  It can't be declared "protected"
330
     * because DB_result is a separate object.
330
     * because DB_result is a separate object.
331
     *
331
     *
332
     * @param resource $result    the query result resource
332
     * @param resource $result    the query result resource
333
     * @param array    $arr       the referenced array to put the data in
333
     * @param array    $arr       the referenced array to put the data in
334
     * @param int      $fetchmode how the resulting array should be indexed
334
     * @param int      $fetchmode how the resulting array should be indexed
335
     * @param int      $rownum    the row number to fetch (0 = first row)
335
     * @param int      $rownum    the row number to fetch (0 = first row)
336
     *
336
     *
337
     * @return mixed  DB_OK on success, NULL when the end of a result set is
337
     * @return mixed  DB_OK on success, NULL when the end of a result set is
338
     *                 reached or on failure
338
     *                 reached or on failure
339
     *
339
     *
340
     * @see DB_result::fetchInto()
340
     * @see DB_result::fetchInto()
341
     */
341
     */
342
    function fetchInto($result, &$arr, $fetchmode, $rownum = null)
342
    function fetchInto($result, &$arr, $fetchmode, $rownum = null)
343
    {
343
    {
344
        if (($rownum !== null) && ($rownum < 0)) {
344
        if (($rownum !== null) && ($rownum < 0)) {
345
            return null;
345
            return null;
346
        }
346
        }
347
        if ($rownum === null) {
347
        if ($rownum === null) {
348
            /*
348
            /*
349
             * Even though fetch_row() should return the next row  if
349
             * Even though fetch_row() should return the next row  if
350
             * $rownum is null, it doesn't in all cases.  Bug 598.
350
             * $rownum is null, it doesn't in all cases.  Bug 598.
351
             */
351
             */
352
            $rownum = 'NEXT';
352
            $rownum = 'NEXT';
353
        } else {
353
        } else {
354
            // Index starts at row 1, unlike most DBMS's starting at 0.
354
            // Index starts at row 1, unlike most DBMS's starting at 0.
355
            $rownum++;
355
            $rownum++;
356
        }
356
        }
357
        if (!$arr = @ifx_fetch_row($result, $rownum)) {
357
        if (!$arr = @ifx_fetch_row($result, $rownum)) {
358
            return null;
358
            return null;
359
        }
359
        }
360
        if ($fetchmode !== DB_FETCHMODE_ASSOC) {
360
        if ($fetchmode !== DB_FETCHMODE_ASSOC) {
361
            $i=0;
361
            $i=0;
362
            $order = array();
362
            $order = array();
363
            foreach ($arr as $val) {
363
            foreach ($arr as $val) {
364
                $order[$i++] = $val;
364
                $order[$i++] = $val;
365
            }
365
            }
366
            $arr = $order;
366
            $arr = $order;
367
        } elseif ($fetchmode == DB_FETCHMODE_ASSOC &&
367
        } elseif ($fetchmode == DB_FETCHMODE_ASSOC &&
368
                  $this->options['portability'] & DB_PORTABILITY_LOWERCASE)
368
                  $this->options['portability'] & DB_PORTABILITY_LOWERCASE)
369
        {
369
        {
370
            $arr = array_change_key_case($arr, CASE_LOWER);
370
            $arr = array_change_key_case($arr, CASE_LOWER);
371
        }
371
        }
372
        if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
372
        if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
373
            $this->_rtrimArrayValues($arr);
373
            $this->_rtrimArrayValues($arr);
374
        }
374
        }
375
        if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
375
        if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
376
            $this->_convertNullArrayValuesToEmpty($arr);
376
            $this->_convertNullArrayValuesToEmpty($arr);
377
        }
377
        }
378
        return DB_OK;
378
        return DB_OK;
379
    }
379
    }
380
 
380
 
381
    // }}}
381
    // }}}
382
    // {{{ numCols()
382
    // {{{ numCols()
383
 
383
 
384
    /**
384
    /**
385
     * Gets the number of columns in a result set
385
     * Gets the number of columns in a result set
386
     *
386
     *
387
     * This method is not meant to be called directly.  Use
387
     * This method is not meant to be called directly.  Use
388
     * DB_result::numCols() instead.  It can't be declared "protected"
388
     * DB_result::numCols() instead.  It can't be declared "protected"
389
     * because DB_result is a separate object.
389
     * because DB_result is a separate object.
390
     *
390
     *
391
     * @param resource $result  PHP's query result resource
391
     * @param resource $result  PHP's query result resource
392
     *
392
     *
393
     * @return int  the number of columns.  A DB_Error object on failure.
393
     * @return int  the number of columns.  A DB_Error object on failure.
394
     *
394
     *
395
     * @see DB_result::numCols()
395
     * @see DB_result::numCols()
396
     */
396
     */
397
    function numCols($result)
397
    function numCols($result)
398
    {
398
    {
399
        if (!$cols = @ifx_num_fields($result)) {
399
        if (!$cols = @ifx_num_fields($result)) {
400
            return $this->ifxRaiseError();
400
            return $this->ifxRaiseError();
401
        }
401
        }
402
        return $cols;
402
        return $cols;
403
    }
403
    }
404
 
404
 
405
    // }}}
405
    // }}}
406
    // {{{ freeResult()
406
    // {{{ freeResult()
407
 
407
 
408
    /**
408
    /**
409
     * Deletes the result set and frees the memory occupied by the result set
409
     * Deletes the result set and frees the memory occupied by the result set
410
     *
410
     *
411
     * This method is not meant to be called directly.  Use
411
     * This method is not meant to be called directly.  Use
412
     * DB_result::free() instead.  It can't be declared "protected"
412
     * DB_result::free() instead.  It can't be declared "protected"
413
     * because DB_result is a separate object.
413
     * because DB_result is a separate object.
414
     *
414
     *
415
     * @param resource $result  PHP's query result resource
415
     * @param resource $result  PHP's query result resource
416
     *
416
     *
417
     * @return bool  TRUE on success, FALSE if $result is invalid
417
     * @return bool  TRUE on success, FALSE if $result is invalid
418
     *
418
     *
419
     * @see DB_result::free()
419
     * @see DB_result::free()
420
     */
420
     */
421
    function freeResult($result)
421
    function freeResult($result)
422
    {
422
    {
423
        return @ifx_free_result($result);
423
        return @ifx_free_result($result);
424
    }
424
    }
425
 
425
 
426
    // }}}
426
    // }}}
427
    // {{{ autoCommit()
427
    // {{{ autoCommit()
428
 
428
 
429
    /**
429
    /**
430
     * Enables or disables automatic commits
430
     * Enables or disables automatic commits
431
     *
431
     *
432
     * @param bool $onoff  true turns it on, false turns it off
432
     * @param bool $onoff  true turns it on, false turns it off
433
     *
433
     *
434
     * @return int  DB_OK on success.  A DB_Error object if the driver
434
     * @return int  DB_OK on success.  A DB_Error object if the driver
435
     *               doesn't support auto-committing transactions.
435
     *               doesn't support auto-committing transactions.
436
     */
436
     */
437
    function autoCommit($onoff = true)
437
    function autoCommit($onoff = true)
438
    {
438
    {
439
        // XXX if $this->transaction_opcount > 0, we should probably
439
        // XXX if $this->transaction_opcount > 0, we should probably
440
        // issue a warning here.
440
        // issue a warning here.
441
        $this->autocommit = $onoff ? true : false;
441
        $this->autocommit = $onoff ? true : false;
442
        return DB_OK;
442
        return DB_OK;
443
    }
443
    }
444
 
444
 
445
    // }}}
445
    // }}}
446
    // {{{ commit()
446
    // {{{ commit()
447
 
447
 
448
    /**
448
    /**
449
     * Commits the current transaction
449
     * Commits the current transaction
450
     *
450
     *
451
     * @return int  DB_OK on success.  A DB_Error object on failure.
451
     * @return int  DB_OK on success.  A DB_Error object on failure.
452
     */
452
     */
453
    function commit()
453
    function commit()
454
    {
454
    {
455
        if ($this->transaction_opcount > 0) {
455
        if ($this->transaction_opcount > 0) {
456
            $result = @ifx_query('COMMIT WORK', $this->connection);
456
            $result = @ifx_query('COMMIT WORK', $this->connection);
457
            $this->transaction_opcount = 0;
457
            $this->transaction_opcount = 0;
458
            if (!$result) {
458
            if (!$result) {
459
                return $this->ifxRaiseError();
459
                return $this->ifxRaiseError();
460
            }
460
            }
461
        }
461
        }
462
        return DB_OK;
462
        return DB_OK;
463
    }
463
    }
464
 
464
 
465
    // }}}
465
    // }}}
466
    // {{{ rollback()
466
    // {{{ rollback()
467
 
467
 
468
    /**
468
    /**
469
     * Reverts the current transaction
469
     * Reverts the current transaction
470
     *
470
     *
471
     * @return int  DB_OK on success.  A DB_Error object on failure.
471
     * @return int  DB_OK on success.  A DB_Error object on failure.
472
     */
472
     */
473
    function rollback()
473
    function rollback()
474
    {
474
    {
475
        if ($this->transaction_opcount > 0) {
475
        if ($this->transaction_opcount > 0) {
476
            $result = @ifx_query('ROLLBACK WORK', $this->connection);
476
            $result = @ifx_query('ROLLBACK WORK', $this->connection);
477
            $this->transaction_opcount = 0;
477
            $this->transaction_opcount = 0;
478
            if (!$result) {
478
            if (!$result) {
479
                return $this->ifxRaiseError();
479
                return $this->ifxRaiseError();
480
            }
480
            }
481
        }
481
        }
482
        return DB_OK;
482
        return DB_OK;
483
    }
483
    }
484
 
484
 
485
    // }}}
485
    // }}}
486
    // {{{ ifxRaiseError()
486
    // {{{ ifxRaiseError()
487
 
487
 
488
    /**
488
    /**
489
     * Produces a DB_Error object regarding the current problem
489
     * Produces a DB_Error object regarding the current problem
490
     *
490
     *
491
     * @param int $errno  if the error is being manually raised pass a
491
     * @param int $errno  if the error is being manually raised pass a
492
     *                     DB_ERROR* constant here.  If this isn't passed
492
     *                     DB_ERROR* constant here.  If this isn't passed
493
     *                     the error information gathered from the DBMS.
493
     *                     the error information gathered from the DBMS.
494
     *
494
     *
495
     * @return object  the DB_Error object
495
     * @return object  the DB_Error object
496
     *
496
     *
497
     * @see DB_common::raiseError(),
497
     * @see DB_common::raiseError(),
498
     *      DB_ifx::errorNative(), DB_ifx::errorCode()
498
     *      DB_ifx::errorNative(), DB_ifx::errorCode()
499
     */
499
     */
500
    function ifxRaiseError($errno = null)
500
    function ifxRaiseError($errno = null)
501
    {
501
    {
502
        if ($errno === null) {
502
        if ($errno === null) {
503
            $errno = $this->errorCode(ifx_error());
503
            $errno = $this->errorCode(ifx_error());
504
        }
504
        }
505
        return $this->raiseError($errno, null, null, null,
505
        return $this->raiseError($errno, null, null, null,
506
                                 $this->errorNative());
506
                                 $this->errorNative());
507
    }
507
    }
508
 
508
 
509
    // }}}
509
    // }}}
510
    // {{{ errorNative()
510
    // {{{ errorNative()
511
 
511
 
512
    /**
512
    /**
513
     * Gets the DBMS' native error code and message produced by the last query
513
     * Gets the DBMS' native error code and message produced by the last query
514
     *
514
     *
515
     * @return string  the DBMS' error code and message
515
     * @return string  the DBMS' error code and message
516
     */
516
     */
517
    function errorNative()
517
    function errorNative()
518
    {
518
    {
519
        return @ifx_error() . ' ' . @ifx_errormsg();
519
        return @ifx_error() . ' ' . @ifx_errormsg();
520
    }
520
    }
521
 
521
 
522
    // }}}
522
    // }}}
523
    // {{{ errorCode()
523
    // {{{ errorCode()
524
 
524
 
525
    /**
525
    /**
526
     * Maps native error codes to DB's portable ones.
526
     * Maps native error codes to DB's portable ones.
527
     *
527
     *
528
     * Requires that the DB implementation's constructor fills
528
     * Requires that the DB implementation's constructor fills
529
     * in the <var>$errorcode_map</var> property.
529
     * in the <var>$errorcode_map</var> property.
530
     *
530
     *
531
     * @param  string  $nativecode  error code returned by the database
531
     * @param  string  $nativecode  error code returned by the database
532
     * @return int a portable DB error code, or DB_ERROR if this DB
532
     * @return int a portable DB error code, or DB_ERROR if this DB
533
     * implementation has no mapping for the given error code.
533
     * implementation has no mapping for the given error code.
534
     */
534
     */
535
    function errorCode($nativecode)
535
    function errorCode($nativecode)
536
    {
536
    {
537
        if (ereg('SQLCODE=(.*)]', $nativecode, $match)) {
537
        if (ereg('SQLCODE=(.*)]', $nativecode, $match)) {
538
            $code = $match[1];
538
            $code = $match[1];
539
            if (isset($this->errorcode_map[$code])) {
539
            if (isset($this->errorcode_map[$code])) {
540
                return $this->errorcode_map[$code];
540
                return $this->errorcode_map[$code];
541
            }
541
            }
542
        }
542
        }
543
        return DB_ERROR;
543
        return DB_ERROR;
544
    }
544
    }
545
 
545
 
546
    // }}}
546
    // }}}
547
    // {{{ tableInfo()
547
    // {{{ tableInfo()
548
 
548
 
549
    /**
549
    /**
550
     * Returns information about a table or a result set
550
     * Returns information about a table or a result set
551
     *
551
     *
552
     * NOTE: only supports 'table' if <var>$result</var> is a table name.
552
     * NOTE: only supports 'table' if <var>$result</var> is a table name.
553
     *
553
     *
554
     * If analyzing a query result and the result has duplicate field names,
554
     * If analyzing a query result and the result has duplicate field names,
555
     * an error will be raised saying
555
     * an error will be raised saying
556
     * <samp>can't distinguish duplicate field names</samp>.
556
     * <samp>can't distinguish duplicate field names</samp>.
557
     *
557
     *
558
     * @param object|string  $result  DB_result object from a query or a
558
     * @param object|string  $result  DB_result object from a query or a
559
     *                                 string containing the name of a table.
559
     *                                 string containing the name of a table.
560
     *                                 While this also accepts a query result
560
     *                                 While this also accepts a query result
561
     *                                 resource identifier, this behavior is
561
     *                                 resource identifier, this behavior is
562
     *                                 deprecated.
562
     *                                 deprecated.
563
     * @param int            $mode    a valid tableInfo mode
563
     * @param int            $mode    a valid tableInfo mode
564
     *
564
     *
565
     * @return array  an associative array with the information requested.
565
     * @return array  an associative array with the information requested.
566
     *                 A DB_Error object on failure.
566
     *                 A DB_Error object on failure.
567
     *
567
     *
568
     * @see DB_common::tableInfo()
568
     * @see DB_common::tableInfo()
569
     * @since Method available since Release 1.6.0
569
     * @since Method available since Release 1.6.0
570
     */
570
     */
571
    function tableInfo($result, $mode = null)
571
    function tableInfo($result, $mode = null)
572
    {
572
    {
573
        if (is_string($result)) {
573
        if (is_string($result)) {
574
            /*
574
            /*
575
             * Probably received a table name.
575
             * Probably received a table name.
576
             * Create a result resource identifier.
576
             * Create a result resource identifier.
577
             */
577
             */
578
            $id = @ifx_query("SELECT * FROM $result WHERE 1=0",
578
            $id = @ifx_query("SELECT * FROM $result WHERE 1=0",
579
                             $this->connection);
579
                             $this->connection);
580
            $got_string = true;
580
            $got_string = true;
581
        } elseif (isset($result->result)) {
581
        } elseif (isset($result->result)) {
582
            /*
582
            /*
583
             * Probably received a result object.
583
             * Probably received a result object.
584
             * Extract the result resource identifier.
584
             * Extract the result resource identifier.
585
             */
585
             */
586
            $id = $result->result;
586
            $id = $result->result;
587
            $got_string = false;
587
            $got_string = false;
588
        } else {
588
        } else {
589
            /*
589
            /*
590
             * Probably received a result resource identifier.
590
             * Probably received a result resource identifier.
591
             * Copy it.
591
             * Copy it.
592
             */
592
             */
593
            $id = $result;
593
            $id = $result;
594
            $got_string = false;
594
            $got_string = false;
595
        }
595
        }
596
 
596
 
597
        if (!is_resource($id)) {
597
        if (!is_resource($id)) {
598
            return $this->ifxRaiseError(DB_ERROR_NEED_MORE_DATA);
598
            return $this->ifxRaiseError(DB_ERROR_NEED_MORE_DATA);
599
        }
599
        }
600
 
600
 
601
        $flds = @ifx_fieldproperties($id);
601
        $flds = @ifx_fieldproperties($id);
602
        $count = @ifx_num_fields($id);
602
        $count = @ifx_num_fields($id);
603
 
603
 
604
        if (count($flds) != $count) {
604
        if (count($flds) != $count) {
605
            return $this->raiseError("can't distinguish duplicate field names");
605
            return $this->raiseError("can't distinguish duplicate field names");
606
        }
606
        }
607
 
607
 
608
        if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
608
        if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
609
            $case_func = 'strtolower';
609
            $case_func = 'strtolower';
610
        } else {
610
        } else {
611
            $case_func = 'strval';
611
            $case_func = 'strval';
612
        }
612
        }
613
 
613
 
614
        $i   = 0;
614
        $i   = 0;
615
        $res = array();
615
        $res = array();
616
 
616
 
617
        if ($mode) {
617
        if ($mode) {
618
            $res['num_fields'] = $count;
618
            $res['num_fields'] = $count;
619
        }
619
        }
620
 
620
 
621
        foreach ($flds as $key => $value) {
621
        foreach ($flds as $key => $value) {
622
            $props = explode(';', $value);
622
            $props = explode(';', $value);
623
            $res[$i] = array(
623
            $res[$i] = array(
624
                'table' => $got_string ? $case_func($result) : '',
624
                'table' => $got_string ? $case_func($result) : '',
625
                'name'  => $case_func($key),
625
                'name'  => $case_func($key),
626
                'type'  => $props[0],
626
                'type'  => $props[0],
627
                'len'   => $props[1],
627
                'len'   => $props[1],
628
                'flags' => $props[4] == 'N' ? 'not_null' : '',
628
                'flags' => $props[4] == 'N' ? 'not_null' : '',
629
            );
629
            );
630
            if ($mode & DB_TABLEINFO_ORDER) {
630
            if ($mode & DB_TABLEINFO_ORDER) {
631
                $res['order'][$res[$i]['name']] = $i;
631
                $res['order'][$res[$i]['name']] = $i;
632
            }
632
            }
633
            if ($mode & DB_TABLEINFO_ORDERTABLE) {
633
            if ($mode & DB_TABLEINFO_ORDERTABLE) {
634
                $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
634
                $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
635
            }
635
            }
636
            $i++;
636
            $i++;
637
        }
637
        }
638
 
638
 
639
        // free the result only if we were called on a table
639
        // free the result only if we were called on a table
640
        if ($got_string) {
640
        if ($got_string) {
641
            @ifx_free_result($id);
641
            @ifx_free_result($id);
642
        }
642
        }
643
        return $res;
643
        return $res;
644
    }
644
    }
645
 
645
 
646
    // }}}
646
    // }}}
647
    // {{{ getSpecialQuery()
647
    // {{{ getSpecialQuery()
648
 
648
 
649
    /**
649
    /**
650
     * Obtains the query string needed for listing a given type of objects
650
     * Obtains the query string needed for listing a given type of objects
651
     *
651
     *
652
     * @param string $type  the kind of objects you want to retrieve
652
     * @param string $type  the kind of objects you want to retrieve
653
     *
653
     *
654
     * @return string  the SQL query string or null if the driver doesn't
654
     * @return string  the SQL query string or null if the driver doesn't
655
     *                  support the object type requested
655
     *                  support the object type requested
656
     *
656
     *
657
     * @access protected
657
     * @access protected
658
     * @see DB_common::getListOf()
658
     * @see DB_common::getListOf()
659
     */
659
     */
660
    function getSpecialQuery($type)
660
    function getSpecialQuery($type)
661
    {
661
    {
662
        switch ($type) {
662
        switch ($type) {
663
            case 'tables':
663
            case 'tables':
664
                return 'SELECT tabname FROM systables WHERE tabid >= 100';
664
                return 'SELECT tabname FROM systables WHERE tabid >= 100';
665
            default:
665
            default:
666
                return null;
666
                return null;
667
        }
667
        }
668
    }
668
    }
669
 
669
 
670
    // }}}
670
    // }}}
671
 
671
 
672
}
672
}
673
 
673
 
674
/*
674
/*
675
 * Local variables:
675
 * Local variables:
676
 * tab-width: 4
676
 * tab-width: 4
677
 * c-basic-offset: 4
677
 * c-basic-offset: 4
678
 * End:
678
 * End:
679
 */
679
 */
680
 
680
 
681
?>
681
?>