1: <?php
2: class ExprTest extends AMysql_TestCase {
3:
4: public function testLiteral()
5: {
6: $stmt = $this->_amysql->newStatement();
7: $expr = $this->_amysql->expr('LOL');
8: $quoted = $stmt->quoteInto('?', $expr);
9: $this->assertEquals('LOL', $quoted);
10: }
11:
12: public function testColumnIn()
13: {
14: $stmt = $this->_amysql->newStatement();
15: $expr = $this->_amysql->expr(AMysql_Expr::COLUMN_IN, 'tableName', array('LOL', 1, 2, 3));
16: $quoted = $stmt->quoteInto('?', $expr);
17: $this->assertEquals(" `tableName` IN ('LOL', 1, 2, 3) ", $quoted);
18: }
19:
20: public function testEscapeLike()
21: {
22: $stmt = $this->_amysql->newStatement();
23: $expr = $this->_amysql->expr(AMysql_Expr::ESCAPE_LIKE, 'lol');
24: $quoted = $stmt->quoteInto('?', $expr);
25: $this->assertEquals("'%lol%' ESCAPE '='", $quoted);
26: }
27:
28: public function testEscapeLikeEquals()
29: {
30: $stmt = $this->_amysql->newStatement();
31: $expr = $this->_amysql->expr(AMysql_Expr::ESCAPE_LIKE, 'lol=');
32: $quoted = $stmt->quoteInto('?', $expr);
33: $this->assertEquals("'%lol==%' ESCAPE '='", $quoted);
34: }
35:
36: public function testEscapeLikePercent()
37: {
38: $stmt = $this->_amysql->newStatement();
39: $expr = $this->_amysql->expr(AMysql_Expr::ESCAPE_LIKE, 'lol%');
40: $quoted = $stmt->quoteInto('?', $expr);
41: $this->assertEquals("'%lol=%%' ESCAPE '='", $quoted);
42: }
43:
44: public function testEscapeCustomPattern()
45: {
46: $stmt = $this->_amysql->newStatement();
47: $expr = $this->_amysql->expr(AMysql_Expr::ESCAPE_LIKE, 'l_o%l', '%%_%s');
48: $quoted = $stmt->quoteInto('?', $expr);
49: $this->assertEquals("'%_l=_o=%l' ESCAPE '='", $quoted);
50: }
51:
52: public function testEscapeColumnName()
53: {
54: $stmt = $this->_amysql->newStatement();
55: $expr = $this->_amysql->expr(AMysql_Expr::ESCAPE_TABLE, 'table');
56: $quoted = $stmt->quoteInto('?', $expr);
57: $this->assertEquals("`table`", $quoted);
58: }
59:
60: public function testEscapeColumnNameWithSpecialChar()
61: {
62: $stmt = $this->_amysql->newStatement();
63: $expr = $this->_amysql->expr(AMysql_Expr::ESCAPE_TABLE, 'tabl`e');
64: $quoted = $stmt->quoteInto('?', $expr);
65: $this->assertEquals("`tabl\\`e`", $quoted);
66: }
67: }
68: