Skip to content

Commit 59e7086

Browse files
committed
Move user guide and move test to live
1 parent e848e00 commit 59e7086

File tree

6 files changed

+28
-43
lines changed

6 files changed

+28
-43
lines changed

tests/system/Database/BaseConnectionTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,6 @@ public function testMagicGetMissing()
165165
$this->assertNull($db->foobar);
166166
}
167167

168-
public function testEscape()
169-
{
170-
$db = new MockConnection($this->options);
171-
172-
$stringArray = [' A simple string ', new RawSql('CURRENT_TIMESTAMP()'), false, null];
173-
174-
$escapedString = $db->escape($stringArray);
175-
176-
$this->assertSame("' A simple string '", $escapedString[0]);
177-
$this->assertSame('CURRENT_TIMESTAMP()', $escapedString[1]);
178-
$this->assertSame(0, $escapedString[2]);
179-
$this->assertSame('NULL', $escapedString[3]);
180-
}
181-
182168
/**
183169
* These tests are intended to confirm the current behavior.
184170
* We do not know if all of these are the correct behavior.

tests/system/Database/Live/EscapeTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace CodeIgniter\Database\Live;
1313

14+
use CodeIgniter\Database\RawSql;
1415
use CodeIgniter\Test\CIUnitTestCase;
1516
use CodeIgniter\Test\DatabaseTestTrait;
1617

@@ -78,4 +79,22 @@ public function testEscapeLikeStringDirect()
7879
$this->expectNotToPerformAssertions();
7980
}
8081
}
82+
83+
public function testEscapeStringArray()
84+
{
85+
$stringArray = [' A simple string ', new RawSql('CURRENT_TIMESTAMP()'), false, null];
86+
87+
$escapedString = $this->db->escape($stringArray);
88+
89+
$this->assertSame("' A simple string '", $escapedString[0]);
90+
$this->assertSame('CURRENT_TIMESTAMP()', $escapedString[1]);
91+
92+
if ($this->db->DBDriver === 'Postgre') {
93+
$this->assertSame('FALSE', $escapedString[2]);
94+
} else {
95+
$this->assertSame(0, $escapedString[2]);
96+
}
97+
98+
$this->assertSame('NULL', $escapedString[3]);
99+
}
81100
}

user_guide_src/source/database/call_function.rst

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,3 @@ The result ID can be accessed from within your result object, like this:
3838

3939
.. literalinclude:: call_function/004.php
4040

41-
$db->escape();
42-
============================
43-
44-
This function enables you to escape a string for database calls. The method
45-
is used by ``BaseBuilder`` for many built in functions. It accepts a string,
46-
array, object or ``CodeIgniter\Database\RawSql``. When ``RawSql`` is used
47-
the string is not escaped. This allows you to call SQL functions and
48-
constants.
49-
50-
.. literalinclude:: call_function/005.php
51-
52-
Here is an example using methods such as ``insert()`` to pass a SQL function.
53-
54-
.. literalinclude:: call_function/006.php

user_guide_src/source/database/call_function/005.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

user_guide_src/source/database/queries.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,17 @@ this:
102102
1. $db->escape()
103103
================
104104

105-
This function determines the data type so
106-
that it can escape only string data. It also automatically adds
107-
single quotes around the data so you don't have to:
105+
This function determines the data type so that it can escape only string
106+
data. It also automatically adds single quotes around the data so you
107+
don't have to:
108108

109109
.. literalinclude:: queries/009.php
110110

111+
When ``RawSql`` is used the string is not escaped. This allows you to call
112+
SQL functions and constants:
113+
114+
.. literalinclude:: queries/030.php
115+
111116
2. $db->escapeString()
112117
======================
113118

user_guide_src/source/database/call_function/006.php renamed to user_guide_src/source/database/queries/030.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
/* Produces:
1313
INSERT INTO mytable (id, title, name, date, last_update)
1414
VALUES (DEFAULT, 'My title', 'My name', '2022-01-01', CURRENT_TIMESTAMP())
15-
*/
15+
*/

0 commit comments

Comments
 (0)