Code Duplication    Length = 40-40 lines in 3 locations

src/engine/dal.php 3 locations

@@ 225-264 (lines=40) @@
222
     *
223
     * @return bool TRUE if transaction is started successfully, FALSE otherwise.
224
     */
225
    public function transaction ()
226
    {
227
        if ($this->is_transaction)
228
        {
229
            debug_write_log(DEBUG_WARNING, '[CDatabase::transaction] Transaction is under progress.');
230
            return FALSE;
231
        }
232
233
        if (DATABASE_DRIVER == DRIVER_MYSQL50)
234
        {
235
            if (extension_loaded('mysqli'))
236
            {
237
                mysqli_query($this->link, 'start transaction');
238
            }
239
            else
240
            {
241
                mysql_query('start transaction', $this->link);
242
            }
243
        }
244
        elseif (DATABASE_DRIVER == DRIVER_MSSQL2K)
245
        {
246
            sqlsrv_begin_transaction($this->link);
247
        }
248
        elseif (DATABASE_DRIVER == DRIVER_ORACLE9)
249
        {
250
            dbx_query($this->link, 'set transaction');
251
        }
252
        elseif (DATABASE_DRIVER == DRIVER_PGSQL80)
253
        {
254
            pg_query($this->link, 'start transaction');
255
        }
256
        else
257
        {
258
            debug_write_log(DEBUG_WARNING, '[CDatabase::transaction] Unknown database driver.');
259
            return FALSE;
260
        }
261
262
        $this->is_transaction = TRUE;
263
        return TRUE;
264
    }
265
266
    /**
267
     * Commits current transaction.
@@ 271-310 (lines=40) @@
268
     *
269
     * @return bool TRUE if transaction is committed successfully, FALSE otherwise.
270
     */
271
    public function commit ()
272
    {
273
        if (!$this->is_transaction)
274
        {
275
            debug_write_log(DEBUG_WARNING, '[CDatabase::commit] No active transactions.');
276
            return FALSE;
277
        }
278
279
        if (DATABASE_DRIVER == DRIVER_MYSQL50)
280
        {
281
            if (extension_loaded('mysqli'))
282
            {
283
                mysqli_query($this->link, 'commit');
284
            }
285
            else
286
            {
287
                mysql_query('commit', $this->link);
288
            }
289
        }
290
        elseif (DATABASE_DRIVER == DRIVER_MSSQL2K)
291
        {
292
            sqlsrv_commit($this->link);
293
        }
294
        elseif (DATABASE_DRIVER == DRIVER_ORACLE9)
295
        {
296
            dbx_query($this->link, 'commit');
297
        }
298
        elseif (DATABASE_DRIVER == DRIVER_PGSQL80)
299
        {
300
            pg_query($this->link, 'commit');
301
        }
302
        else
303
        {
304
            debug_write_log(DEBUG_WARNING, '[CDatabase::commit] Unknown database driver.');
305
            return FALSE;
306
        }
307
308
        $this->is_transaction = FALSE;
309
        return TRUE;
310
    }
311
312
    /**
313
     * Rolls back current transaction.
@@ 317-356 (lines=40) @@
314
     *
315
     * @return bool TRUE if transaction is rolled back successfully, FALSE otherwise.
316
     */
317
    public function rollback ()
318
    {
319
        if (!$this->is_transaction)
320
        {
321
            debug_write_log(DEBUG_WARNING, '[CDatabase::rollback] No active transactions.');
322
            return FALSE;
323
        }
324
325
        if (DATABASE_DRIVER == DRIVER_MYSQL50)
326
        {
327
            if (extension_loaded('mysqli'))
328
            {
329
                mysqli_query($this->link, 'rollback');
330
            }
331
            else
332
            {
333
                mysql_query('rollback', $this->link);
334
            }
335
        }
336
        elseif (DATABASE_DRIVER == DRIVER_MSSQL2K)
337
        {
338
            sqlsrv_rollback($this->link);
339
        }
340
        elseif (DATABASE_DRIVER == DRIVER_ORACLE9)
341
        {
342
            dbx_query($this->link, 'rollback');
343
        }
344
        elseif (DATABASE_DRIVER == DRIVER_PGSQL80)
345
        {
346
            pg_query($this->link, 'rollback');
347
        }
348
        else
349
        {
350
            debug_write_log(DEBUG_WARNING, '[CDatabase::rollback] Unknown database driver.');
351
            return FALSE;
352
        }
353
354
        $this->is_transaction = FALSE;
355
        return TRUE;
356
    }
357
}
358
359
//------------------------------------------------------------------------------