2013-04-03 06:27:11 +02:00
|
|
|
<?php
|
|
|
|
|
2017-11-16 22:58:14 +01:00
|
|
|
namespace SilverStripe\PostgreSQL\Tests;
|
|
|
|
|
2016-09-01 06:22:17 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2016-07-04 02:44:09 +02:00
|
|
|
use SilverStripe\PostgreSQL\PostgreSQLConnector;
|
|
|
|
|
2015-12-17 19:18:01 +01:00
|
|
|
class PostgreSQLConnectorTest extends SapphireTest
|
|
|
|
{
|
|
|
|
public function testSubstitutesPlaceholders()
|
|
|
|
{
|
|
|
|
$connector = new PostgreSQLConnector();
|
2013-04-03 06:27:11 +02:00
|
|
|
|
2015-12-17 19:18:01 +01:00
|
|
|
// basic case
|
|
|
|
$this->assertEquals(
|
|
|
|
"SELECT * FROM Table WHERE ID = $1",
|
|
|
|
$connector->replacePlaceholders("SELECT * FROM Table WHERE ID = ?")
|
|
|
|
);
|
2013-04-03 06:27:11 +02:00
|
|
|
|
2015-12-17 19:18:01 +01:00
|
|
|
// Multiple variables
|
|
|
|
$this->assertEquals(
|
|
|
|
"SELECT * FROM Table WHERE ID = $1 AND Name = $2",
|
|
|
|
$connector->replacePlaceholders("SELECT * FROM Table WHERE ID = ? AND Name = ?")
|
|
|
|
);
|
2013-04-03 06:27:11 +02:00
|
|
|
|
2015-12-17 19:18:01 +01:00
|
|
|
// Ignoring question mark placeholders within string literals
|
|
|
|
$this->assertEquals(
|
2017-11-16 22:58:14 +01:00
|
|
|
"SELECT * FROM Table WHERE ID = $1 AND Name = $2 AND Content = '<p>What is love?</p>'",
|
2015-12-17 19:18:01 +01:00
|
|
|
$connector->replacePlaceholders(
|
|
|
|
"SELECT * FROM Table WHERE ID = ? AND Name = ? AND Content = '<p>What is love?</p>'"
|
|
|
|
)
|
|
|
|
);
|
2013-04-03 06:27:11 +02:00
|
|
|
|
2015-12-17 19:18:01 +01:00
|
|
|
// Ignoring question mark placeholders within string literals with escaped slashes
|
|
|
|
$this->assertEquals(
|
2017-11-16 22:58:14 +01:00
|
|
|
"SELECT * FROM Table WHERE ID = $1 AND Title = '\\'' AND Content = '<p>What is love?</p>' AND Name = $2",
|
2015-12-17 19:18:01 +01:00
|
|
|
$connector->replacePlaceholders(
|
|
|
|
"SELECT * FROM Table WHERE ID = ? AND Title = '\\'' AND Content = '<p>What is love?</p>' AND Name = ?"
|
|
|
|
)
|
|
|
|
);
|
2013-04-03 06:27:11 +02:00
|
|
|
|
2015-12-17 19:18:01 +01:00
|
|
|
// same as above, but use double single quote escape syntax
|
|
|
|
$this->assertEquals(
|
2017-11-16 22:58:14 +01:00
|
|
|
"SELECT * FROM Table WHERE ID = $1 AND Title = '''' AND Content = '<p>What is love?</p>' AND Name = $2",
|
2015-12-17 19:18:01 +01:00
|
|
|
$connector->replacePlaceholders(
|
|
|
|
"SELECT * FROM Table WHERE ID = ? AND Title = '''' AND Content = '<p>What is love?</p>' AND Name = ?"
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2013-04-03 06:27:11 +02:00
|
|
|
}
|