db backup prior to drupal security update
[yaffs-website] / vendor / gabordemooij / redbean / testing / RedUNIT / Sqlite / Parambind.php
1 <?php
2
3 namespace RedUNIT\Sqlite;
4
5 use RedUNIT\Sqlite as Sqlite;
6 use RedBeanPHP\Facade as R;
7
8 /**
9  * Parambind
10  *
11  * Tests the parameter binding functionality in RedBeanPHP.
12  * These test scenarios include for instance: NULL handling,
13  * binding parameters in LIMIT clauses and so on.
14  *
15  * @file    RedUNIT/Sqlite/Parambind.php
16  * @desc    Tests\PDO parameter binding.
17  * @author  Gabor de Mooij and the RedBeanPHP Community
18  * @license New BSD/GPLv2
19  *
20  * (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community.
21  * This source file is subject to the New BSD/GPLv2 License that is bundled
22  * with this source code in the file license.txt.
23  */
24 class Parambind extends Sqlite
25 {
26         /**
27          * Test parameter binding with SQLite.
28          *
29          * @return void
30          */
31         public function testParamBindWithSQLite()
32         {
33                 $toolbox = R::getToolBox();
34                 $adapter = $toolbox->getDatabaseAdapter();
35                 $writer  = $toolbox->getWriter();
36                 $redbean = $toolbox->getRedBean();
37                 $pdo     = $adapter->getDatabase();
38                 asrt( (int) $adapter->getCell( "SELECT 123" ), 123 );
39                 asrt( (int) $adapter->getCell( "SELECT ?", array( "987" ) ), 987 );
40                 asrt( (int) $adapter->getCell( "SELECT ?+?", array( "987", "2" ) ), 989 );
41                 asrt( (int) $adapter->getCell(
42                         "SELECT :numberOne+:numberTwo",
43                         array(
44                                 ":numberOne" => 42,
45                                 ":numberTwo" => 50 )
46                         ),
47                         92
48                 );
49                 $pair = $adapter->getAssoc( "SELECT 'thekey','thevalue' " );
50                 asrt( is_array( $pair ), TRUE );
51                 asrt( count( $pair ), 1 );
52                 asrt( isset( $pair["thekey"] ), TRUE );
53                 asrt( $pair["thekey"], "thevalue" );
54                 testpack( 'Test whether we can properly bind and receive NULL values' );
55                 asrt( $adapter->getCell( 'SELECT :nil ', array( ':nil' => 'NULL' ) ), 'NULL' );
56                 asrt( $adapter->getCell( 'SELECT :nil ', array( ':nil' => NULL ) ), NULL );
57                 asrt( $adapter->getCell( 'SELECT ? ', array( 'NULL' ) ), 'NULL' );
58                 asrt( $adapter->getCell( 'SELECT ? ', array( NULL ) ), NULL );
59         }
60 }