/** * Test that value() quotes set values even when numeric. * * @return void */ public function testSetValue() { $column = "set('a','b','c')"; $result = $this->Dbo->value('1', $column); $this->assertEquals("'1'", $result); $result = $this->Dbo->value(1, $column); $this->assertEquals("'1'", $result); $result = $this->Dbo->value('a', $column); $this->assertEquals("'a'", $result); }
/** * SQL file header * * @param $datasource * @return string */ function _createSqlDumpHeader($datasource) { $sql = array(); $sql[] = $this->hr(0); $sql[] = '-- ' . $this->message; $sql[] = '-- generated on: ' . date('Y-m-d H:i:s') . ' : ' . time(); $sql[] = $this->hr(0); $sql[] = ''; if (preg_match('/^mysql/i', $this->DataSource->config['driver'])) { $sql[] = 'use ' . $this->DataSource->name($this->DataSource->config['database']) . ';'; } if (!empty($this->DataSource->config['encoding'])) { $sql[] = 'SET NAMES ' . $this->DataSource->value($this->DataSource->config['encoding']) . ';'; } return $this->out($sql); }
/** * Gather all the data for creating a new user. * * @param string $mode * @return string */ protected function _newUser($mode) { $userMap = Configure::read('Forum.userMap'); switch ($mode) { case 'username': $username = trim($this->in('<question>Username:</question>')); if (!$username) { $username = $this->_newUser($mode); } else { $result = $this->db->fetchRow(sprintf("SELECT COUNT(*) AS `count` FROM `%s` AS `User` WHERE `%s` = %s", $this->install['table'], $userMap['username'], $this->db->value($username))); if ($this->db->hasResult() && $result[0]['count']) { $this->out('<error>Username already exists, please try again</error>'); $username = $this->_newUser($mode); } } return $username; break; case 'password': $password = trim($this->in('<question>Password:</question>')); if (!$password) { $password = $this->_newUser($mode); } return $password; break; case 'email': $email = trim($this->in('<question>Email:</question>')); if (!$email) { $email = $this->_newUser($mode); } else { if (!Validation::email($email)) { $this->out('<error>Invalid email address, please try again</error>'); $email = $this->_newUser($mode); } else { $result = $this->db->fetchRow(sprintf("SELECT COUNT(*) AS `count` FROM `%s` AS `User` WHERE `%s` = %s", $this->install['table'], $userMap['email'], $this->db->value($email))); if ($this->db->hasResult() && $result[0]['count']) { $this->out('<error>Email already exists, please try again</error>'); $email = $this->_newUser($mode); } } } return $email; break; } return null; }
/** * Returns a quoted and escaped string of $data for use in an SQL statement. * * @param string $data String to be prepared for use in an SQL statement * @param string $column The column into which this data will be inserted * @return string Quoted and escaped data */ public function value($data, $column = null, $null = true) { if ($data === null || is_array($data) || is_object($data)) { return parent::value($data, $column); } if (in_array($data, array('{$__cakeID__$}', '{$__cakeForeignKey__$}'), true)) { return $data; } if (empty($column)) { $column = $this->introspectType($data); } switch ($column) { case 'string': case 'text': return 'N' . $this->_connection->quote($data, PDO::PARAM_STR); default: return parent::value($data, $column); } }
/** * Returns a quoted and escaped string of $data for use in an SQL statement. * * @param string $data String to be prepared for use in an SQL statement * @return string Quoted and escaped * @access public */ function value($data, $column = null, $safe = false) { $parent = parent::value($data, $column, $safe); if ($parent != null) { return $parent; } if ($data === null || is_array($data) && empty($data)) { return 'NULL'; } if ($data === '') { return "''"; } switch ($column) { case 'boolean': $data = $this->boolean((bool) $data); break; default: $data = $this->connection->quote($data); return $data; break; } return "'" . $data . "'"; }
/** * Test Dbo value method * * @access public */ function testQuoting() { $result = $this->db->fields($this->model); $expected = array('`AdodbTestModel`.`id` AS `AdodbTestModel__id`', '`AdodbTestModel`.`client_id` AS `AdodbTestModel__client_id`', '`AdodbTestModel`.`name` AS `AdodbTestModel__name`', '`AdodbTestModel`.`login` AS `AdodbTestModel__login`', '`AdodbTestModel`.`passwd` AS `AdodbTestModel__passwd`', '`AdodbTestModel`.`addr_1` AS `AdodbTestModel__addr_1`', '`AdodbTestModel`.`addr_2` AS `AdodbTestModel__addr_2`', '`AdodbTestModel`.`zip_code` AS `AdodbTestModel__zip_code`', '`AdodbTestModel`.`city` AS `AdodbTestModel__city`', '`AdodbTestModel`.`country` AS `AdodbTestModel__country`', '`AdodbTestModel`.`phone` AS `AdodbTestModel__phone`', '`AdodbTestModel`.`fax` AS `AdodbTestModel__fax`', '`AdodbTestModel`.`url` AS `AdodbTestModel__url`', '`AdodbTestModel`.`email` AS `AdodbTestModel__email`', '`AdodbTestModel`.`comments` AS `AdodbTestModel__comments`', '`AdodbTestModel`.`last_login` AS `AdodbTestModel__last_login`', '`AdodbTestModel`.`created` AS `AdodbTestModel__created`', '`AdodbTestModel`.`updated` AS `AdodbTestModel__updated`'); $this->assertEqual($result, $expected); $expected = "'1.2'"; $result = $this->db->value(1.2, 'float'); $this->assertEqual($expected, $result); $expected = "'1,2'"; $result = $this->db->value('1,2', 'float'); $this->assertEqual($expected, $result); $expected = "'4713e29446'"; $result = $this->db->value('4713e29446'); $this->assertEqual($expected, $result); $expected = "'10010001'"; $result = $this->db->value('10010001'); $this->assertEqual($expected, $result); $expected = "'00010010001'"; $result = $this->db->value('00010010001'); $this->assertEqual($expected, $result); }
/** * {@inheritDoc} */ public function value($data, $column = null, $null = true) { $value = parent::value($data, $column, $null); if ($column === 'uuid' && is_scalar($data) && $data === '') { return 'NULL'; } return $value; }
/** * Prepares a value, or an array of values for database queries by quoting and escaping them. * * @param mixed $data A value or an array of values to prepare. * @param string $column The column into which this data will be inserted * @param boolean $read Value to be used in READ or WRITE context * @return mixed Prepared value or array of values. * @access public */ public function value($data, $column = null, $read = true) { $return = parent::value($data, $column, $read); if ($return === null && $data !== null) { return $data; } return $return; }
/** * Returns a quoted and escaped string of $data for use in an SQL statement. * * @param string $data String to be prepared for use in an SQL statement * @param string $column * @param int $safe * @return string Quoted and escaped * @access public */ function value($data, $column = null, $safe = false) { $parent = parent::value($data, $column, $safe); if ($parent != null) { return $parent; } if ($data === null) { return 'NULL'; } switch ($column) { case 'boolean': if ($data === '') { return 0; } $data = $this->boolean((bool) $data); break; case 'integer': if ($data === '') { return 'NULL'; } break; case 'datetime': if ($data) { $data = trim(str_replace('/', '-', $data)); } if ($data === '' || $data == '0000-00-00 00:00:00') { return "''"; } break; default: if ($data === '') { return "''"; } $data = $this->connection->quote($data); return $data; break; } return "'" . $data . "'"; }
/** * SQL用にエスケープ処理を行う * * @param string $data String to be prepared for use in an SQL statement * @param string $column The column into which this data will be inserted * @param boolean $safe Whether or not numeric data should be handled automagically if no column data is provided * @return string Quoted and escaped data * @access public */ function value($data, $column = null, $safe = false) { $parent = parent::value($data, $column, $safe); if ($parent != null) { return $parent; } elseif ($data === null) { return 'NULL'; } elseif ($data === '') { return "''"; } if (empty($column)) { $column = $this->introspectType($data); } switch ($column) { case 'boolean': return $this->boolean((bool) $data); break; case 'integer': case 'float': if (is_int($data) || is_float($data) || is_numeric($data) && strpos($data, ',') === false && $data[0] != '0' && strpos($data, 'e') === false) { return $data; } default: $data = "'" . $this->escapeString($data) . "'"; break; } return $data; }
/** * testQuoting method * * @return void */ public function testQuoting() { $expected = "1.2"; $result = $this->db->value(1.2, 'float'); $this->assertSame($expected, $result); $expected = "'1,2'"; $result = $this->db->value('1,2', 'float'); $this->assertSame($expected, $result); $expected = 'NULL'; $result = $this->db->value('', 'integer'); $this->assertSame($expected, $result); $expected = 'NULL'; $result = $this->db->value('', 'float'); $this->assertSame($expected, $result); $expected = "''"; $result = $this->db->value('', 'binary'); $this->assertSame($expected, $result); }
/** * Returns a quoted and escaped string of $data for use in an SQL statement. * * @param string $data String to be prepared for use in an SQL statement * @param string $column The column into which this data will be inserted * @return string Quoted and escaped * @todo Add logic that formats/escapes data based on column type */ function value($data, $column = null) { $parent = parent::value($data, $column); if ($parent != null) { return $parent; } if ($data === null) { return 'NULL'; } // $data = mysql_real_escape_string($data, $this->connection); if (!is_numeric($data)) { $return = "'" . $data . "'"; } else { $return = $data; } return $return; }
/** * Returns a quoted and escaped string of $data for use in an SQL statement. * * @param string $data String to be prepared for use in an SQL statement * @return string Quoted and escaped */ function value($data, $column = null, $safe = false) { $parent = parent::value($data, $column, $safe); if ($parent != null) { return $parent; } if ($data === null) { return 'NULL'; } if ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') { return "''"; } switch ($column) { case 'boolean': $data = $this->boolean((bool) $data); break; case 'integer': case 'float': if ($data === '') { return 'NULL'; } default: $data = sqlite_escape_string($data); break; } return "'" . $data . "'"; }
/** * Returns a quoted and escaped string of $data for use in an SQL statement. * * @param string $data String to be prepared for use in an SQL statement * @param string $column The column into which this data will be inserted * @return string Quoted and escaped * @todo Add logic that formats/escapes data based on column type */ function value($data, $column = null) { $parent = parent::value($data, $column); if ($parent != null) { return $parent; } if ($data === null) { return 'NULL'; } if (!is_numeric($data)) { $return = "'" . $data . "'"; } else { $return = $data; } return $return; }
/** * Returns a quoted and escaped string of $data for use in an SQL statement. * * @param string $data String to be prepared for use in an SQL statement * @param string $column The column into which this data will be inserted * @return string Quoted and escaped * @todo Add logic that formats/escapes data based on column type */ function value($data, $column = null) { $parent = parent::value($data, $column); if ($parent != null) { return $parent; } if ($data === null || is_array($data) && empty($data)) { return 'NULL'; } if (!is_numeric($data)) { return "'" . $data . "'"; } return $data; }
/** * Returns a quoted and escaped string of $data for use in an SQL statement. * * @param string $data String to be prepared for use in an SQL statement * @param string $column The column into which this data will be inserted * @return string Quoted and escaped * @todo Add logic that formats/escapes data based on column type */ function value($data, $column = null) { $parent = parent::value($data, $column); if ($parent != null) { return $parent; } if ($data === null) { return 'NULL'; } switch ($column) { case 'inet': if (!strlen($data)) { return 'DEFAULT'; } else { $data = pg_escape_string($data); } break; case 'integer': if ($data === '') { return 'DEFAULT'; } else { $data = pg_escape_string($data); } break; case 'binary': $data = pg_escape_bytea($data); break; case 'boolean': default: if ($data === true) { return 'TRUE'; } elseif ($data === false) { return 'FALSE'; } $data = pg_escape_string($data); break; } return "'" . $data . "'"; }
/** * Returns a quoted and escaped string of $data for use in an SQL statement. * * @param string $data String to be prepared for use in an SQL statement * @return string Quoted and escaped * @access public */ function value($data, $column = null, $safe = false) { $parent = parent::value($data, $column, $safe); if ($parent != null) { return $parent; } if ($data === null) { return 'NULL'; } if ($data === '') { return "''"; } switch ($column) { case 'date': $date = new DateTime($data); $data = $date->format('Y-m-d H:i:s'); $data = "TO_DATE('{$data}', 'YYYY-MM-DD HH24:MI:SS')"; break; case 'integer': case 'float': case null: if (is_numeric($data)) { break; } default: $data = str_replace("'", "''", $data); $data = "'{$data}'"; break; } return $data; }
/** * {@inheritDoc} */ public function value($data, $column = NULL, $null = TRUE) { $value = parent::value($data, $column, $null); if (is_numeric($value) && substr($column, 0, 3) === 'set') { return $this->_connection->quote($value); } return $value; }
/** * Returns a quoted and escaped string of $data for use in an SQL statement. * * @param string $data String to be prepared for use in an SQL statement * @param string $column The column into which this data will be inserted * @param boolean $safe Whether or not numeric data should be handled automagically if no column data is provided * @return string Quoted and escaped data */ function value($data, $column = null, $safe = false) { $parent = parent::value($data, $column, $safe); if ($parent != null) { return $parent; } if ($data === null) { return 'NULL'; } if (in_array($column, array('integer', 'float', 'binary')) && $data === '') { return 'NULL'; } if ($data === '') { return "''"; } switch ($column) { case 'boolean': $data = $this->boolean((bool) $data); break; default: if (get_magic_quotes_gpc()) { $data = stripslashes(str_replace("'", "''", $data)); } else { $data = str_replace("'", "''", $data); } break; } if (in_array($column, array('integer', 'float', 'binary')) && is_numeric($data)) { return $data; } return "'" . $data . "'"; }
/** * Returns a quoted and escaped string of $data for use in an SQL statement. * * @param string $data String to be prepared for use in an SQL statement * @param string $column The column into which this data will be inserted * @param boolean $safe Whether or not numeric data should be handled automagically if no column data is provided * @return string Quoted and escaped data */ function value($data, $column = null, $safe = false) { $parent = parent::value($data, $column, $safe); if ($parent != null) { return $parent; } if ($data === null) { return 'NULL'; } if ($data === '') { return "''"; } switch ($column) { case 'boolean': $data = $this->boolean((bool) $data); break; default: $data = str_replace("'", "''", $data); break; } return "'" . $data . "'"; }
/** * Returns a quoted and escaped string of $data for use in an SQL statement. * * @param string $data String to be prepared for use in an SQL statement * @param string $column The column into which this data will be inserted * @param boolean $read Value to be used in READ or WRITE context * @return string Quoted and escaped * @todo Add logic that formats/escapes data based on column type */ function value($data, $column = null, $read = true) { $parent = parent::value($data, $column); if ($parent != null) { return $parent; } if ($data === null) { return 'NULL'; } if (empty($column)) { $column = $this->introspectType($data); } switch ($column) { case 'inet': case 'float': case 'integer': case 'date': case 'datetime': case 'timestamp': case 'time': if ($data === '') { return $read ? 'NULL' : 'DEFAULT'; } case 'binary': $data = pg_escape_bytea($data); break; case 'boolean': if ($data === true || $data === 't' || $data === 'true') { return 'TRUE'; } elseif ($data === false || $data === 'f' || $data === 'false') { return 'FALSE'; } return !empty($data) ? 'TRUE' : 'FALSE'; break; default: $data = pg_escape_string($data); break; } return "'" . $data . "'"; }
/** * test that date columns do not generate errors with null and nullish values. * * @return void **/ function testDateAsNull() { $this->assertEqual($this->db2->value(null, 'date'), 'NULL'); $this->assertEqual($this->db2->value('', 'date'), 'NULL'); $this->assertEqual($this->db2->value('', 'datetime'), 'NULL'); $this->assertEqual($this->db2->value(null, 'datetime'), 'NULL'); $this->assertEqual($this->db2->value('', 'timestamp'), 'NULL'); $this->assertEqual($this->db2->value(null, 'timestamp'), 'NULL'); }
/** * Returns a quoted and escaped string of $data for use in an SQL statement. * * @param string $data String to be prepared for use in an SQL statement * @param string $column The column into which this data will be inserted * @param boolean $safe Whether or not numeric data should be handled automagically if no column data is provided * @return string Quoted and escaped data */ function value($data, $column = null, $safe = false) { $parent = parent::value($data, $column, $safe); if ($parent != null) { return $parent; } if ($data === null) { return 'NULL'; } if ($data === '') { return "''"; } switch ($column) { case 'boolean': $data = $this->boolean((bool) $data); break; case 'integer': case 'float': case null: if (is_numeric($data) && strpos($data, ',') === false && $data[0] != '0' && strpos($data, 'e') === false) { break; } default: $data = "'" . mysqli_real_escape_string($this->connection, $data) . "'"; break; } return $data; }
/** * testQuoting method * * @access public * @return void */ function testQuoting() { $result = $this->db->fields($this->model); $expected = array('[MssqlTestModel].[id] AS [MssqlTestModel__0]', '[MssqlTestModel].[client_id] AS [MssqlTestModel__1]', '[MssqlTestModel].[name] AS [MssqlTestModel__2]', '[MssqlTestModel].[login] AS [MssqlTestModel__3]', '[MssqlTestModel].[passwd] AS [MssqlTestModel__4]', '[MssqlTestModel].[addr_1] AS [MssqlTestModel__5]', '[MssqlTestModel].[addr_2] AS [MssqlTestModel__6]', '[MssqlTestModel].[zip_code] AS [MssqlTestModel__7]', '[MssqlTestModel].[city] AS [MssqlTestModel__8]', '[MssqlTestModel].[country] AS [MssqlTestModel__9]', '[MssqlTestModel].[phone] AS [MssqlTestModel__10]', '[MssqlTestModel].[fax] AS [MssqlTestModel__11]', '[MssqlTestModel].[url] AS [MssqlTestModel__12]', '[MssqlTestModel].[email] AS [MssqlTestModel__13]', '[MssqlTestModel].[comments] AS [MssqlTestModel__14]', 'CONVERT(VARCHAR(20), [MssqlTestModel].[last_login], 20) AS [MssqlTestModel__15]', '[MssqlTestModel].[created] AS [MssqlTestModel__16]', 'CONVERT(VARCHAR(20), [MssqlTestModel].[updated], 20) AS [MssqlTestModel__17]'); $this->assertEqual($result, $expected); $expected = "1.2"; $result = $this->db->value(1.2, 'float'); $this->assertIdentical($expected, $result); $expected = "'1,2'"; $result = $this->db->value('1,2', 'float'); $this->assertIdentical($expected, $result); }
/** * testIntrospectType method * * @return void */ public function testIntrospectType() { $this->assertEquals('integer', $this->Dbo->introspectType(0)); $this->assertEquals('integer', $this->Dbo->introspectType(2)); $this->assertEquals('string', $this->Dbo->introspectType('2')); $this->assertEquals('string', $this->Dbo->introspectType('2.2')); $this->assertEquals('float', $this->Dbo->introspectType(2.2)); $this->assertEquals('string', $this->Dbo->introspectType('stringme')); $this->assertEquals('string', $this->Dbo->introspectType('0stringme')); $data = array(2.2); $this->assertEquals('float', $this->Dbo->introspectType($data)); $data = array('2.2'); $this->assertEquals('float', $this->Dbo->introspectType($data)); $data = array(2); $this->assertEquals('integer', $this->Dbo->introspectType($data)); $data = array('2'); $this->assertEquals('integer', $this->Dbo->introspectType($data)); $data = array('string'); $this->assertEquals('string', $this->Dbo->introspectType($data)); $data = array(2.2, '2.2'); $this->assertEquals('float', $this->Dbo->introspectType($data)); $data = array(2, '2'); $this->assertEquals('integer', $this->Dbo->introspectType($data)); $data = array('string one', 'string two'); $this->assertEquals('string', $this->Dbo->introspectType($data)); $data = array('2.2', 3); $this->assertEquals('integer', $this->Dbo->introspectType($data)); $data = array('2.2', '0stringme'); $this->assertEquals('string', $this->Dbo->introspectType($data)); $data = array(2.2, 3); $this->assertEquals('integer', $this->Dbo->introspectType($data)); $data = array(2.2, '0stringme'); $this->assertEquals('string', $this->Dbo->introspectType($data)); $data = array(2, 'stringme'); $this->assertEquals('string', $this->Dbo->introspectType($data)); $data = array(2, '2.2', 'stringgme'); $this->assertEquals('string', $this->Dbo->introspectType($data)); $data = array(2, '2.2'); $this->assertEquals('integer', $this->Dbo->introspectType($data)); $data = array(2, 2.2); $this->assertEquals('integer', $this->Dbo->introspectType($data)); // null $result = $this->Dbo->value(null, 'boolean'); $this->assertEquals('NULL', $result); // EMPTY STRING $result = $this->Dbo->value('', 'boolean'); $this->assertEquals("'0'", $result); // BOOLEAN $result = $this->Dbo->value('true', 'boolean'); $this->assertEquals("'1'", $result); $result = $this->Dbo->value('false', 'boolean'); $this->assertEquals("'1'", $result); $result = $this->Dbo->value(true, 'boolean'); $this->assertEquals("'1'", $result); $result = $this->Dbo->value(false, 'boolean'); $this->assertEquals("'0'", $result); $result = $this->Dbo->value(1, 'boolean'); $this->assertEquals("'1'", $result); $result = $this->Dbo->value(0, 'boolean'); $this->assertEquals("'0'", $result); $result = $this->Dbo->value('abc', 'boolean'); $this->assertEquals("'1'", $result); $result = $this->Dbo->value(1.234, 'boolean'); $this->assertEquals("'1'", $result); $result = $this->Dbo->value('1.234e05', 'boolean'); $this->assertEquals("'1'", $result); // NUMBERS $result = $this->Dbo->value(123, 'integer'); $this->assertEquals(123, $result); $result = $this->Dbo->value('123', 'integer'); $this->assertEquals('123', $result); $result = $this->Dbo->value('0123', 'integer'); $this->assertEquals("'0123'", $result); $result = $this->Dbo->value('0x123ABC', 'integer'); $this->assertEquals("'0x123ABC'", $result); $result = $this->Dbo->value('0x123', 'integer'); $this->assertEquals("'0x123'", $result); $result = $this->Dbo->value(1.234, 'float'); $this->assertEquals(1.234, $result); $result = $this->Dbo->value('1.234', 'float'); $this->assertEquals('1.234', $result); $result = $this->Dbo->value(' 1.234 ', 'float'); $this->assertEquals("' 1.234 '", $result); $result = $this->Dbo->value('1.234e05', 'float'); $this->assertEquals("'1.234e05'", $result); $result = $this->Dbo->value('1.234e+5', 'float'); $this->assertEquals("'1.234e+5'", $result); $result = $this->Dbo->value('1,234', 'float'); $this->assertEquals("'1,234'", $result); $result = $this->Dbo->value('FFF', 'integer'); $this->assertEquals("'FFF'", $result); $result = $this->Dbo->value('abc', 'integer'); $this->assertEquals("'abc'", $result); // STRINGS $result = $this->Dbo->value('123', 'string'); $this->assertEquals("'123'", $result); $result = $this->Dbo->value(123, 'string'); $this->assertEquals("'123'", $result); $result = $this->Dbo->value(1.234, 'string'); $this->assertEquals("'1.234'", $result); $result = $this->Dbo->value('abc', 'string'); $this->assertEquals("'abc'", $result); $result = $this->Dbo->value(' abc ', 'string'); $this->assertEquals("' abc '", $result); $result = $this->Dbo->value('a bc', 'string'); $this->assertEquals("'a bc'", $result); }
/** * Returns a quoted and escaped string of $data for use in an SQL statement. * * @param string $data String to be prepared for use in an SQL statement * @param string $column The column into which this data will be inserted * @return string Quoted and escaped * @todo Add logic that formats/escapes data based on column type */ public function value($data, $column = null, $safe = false) { $parent = parent::value($data, $column, $safe); if ($parent != null) { return $parent; } if ($data === null || is_array($data) && empty($data)) { return 'NULL'; } if ($data === '') { return "''"; } switch ($column) { case 'boolean': $data = $this->boolean((bool) $data); break; case 'integer': $data = intval($data); break; default: $data = str_replace("'", "''", $data); break; } if ($column === 'integer' || $column === 'float') { return $data; } return "'" . $data . "'"; }
/** * testValueQuoting method * * @access public * @return void */ function testValueQuoting() { $this->assertEqual($this->db2->value('0', 'integer'), "'0'"); $this->assertEqual($this->db2->value('', 'integer'), 'NULL'); $this->assertEqual($this->db2->value('', 'float'), 'NULL'); $this->assertEqual($this->db2->value('', 'integer', false), "DEFAULT"); $this->assertEqual($this->db2->value('', 'float', false), "DEFAULT"); $this->assertEqual($this->db2->value('0.0', 'float'), "'0.0'"); $this->assertEqual($this->db2->value('t', 'boolean'), "TRUE"); $this->assertEqual($this->db2->value('f', 'boolean'), "FALSE"); $this->assertEqual($this->db2->value(true), "TRUE"); $this->assertEqual($this->db2->value(false), "FALSE"); $this->assertEqual($this->db2->value('t'), "'t'"); $this->assertEqual($this->db2->value('f'), "'f'"); $this->assertEqual($this->db2->value('true', 'boolean'), 'TRUE'); $this->assertEqual($this->db2->value('false', 'boolean'), 'FALSE'); $this->assertEqual($this->db2->value('', 'boolean'), 'FALSE'); $this->assertEqual($this->db2->value(0, 'boolean'), 'FALSE'); $this->assertEqual($this->db2->value(1, 'boolean'), 'TRUE'); $this->assertEqual($this->db2->value('1', 'boolean'), 'TRUE'); $this->assertEqual($this->db2->value(null, 'boolean'), "NULL"); }
/** * Returns a quoted and escaped string of $data for use in an SQL statement. * * @param string $data String to be prepared for use in an SQL statement * @param string $column The column into which this data will be inserted * @param boolean $safe Whether or not numeric data should be handled automagically if no column data is provided * @return string Quoted and escaped data */ function value($data, $column = null, $safe = false) { $parent = parent::value($data, $column, $safe); if ($parent != null) { return $parent; } if ($data === null) { return 'NULL'; } if ($data === '') { return "''"; } switch ($column) { case 'boolean': $data = $this->boolean((bool) $data); break; default: if (get_magic_quotes_gpc()) { $data = stripslashes(r("'", "''", $data)); } else { $data = r("'", "''", $data); } break; } return "'" . $data . "'"; }
/** * test that date and time columns do not generate errors with null and nullish values. * * @return void */ public function testDateAndTimeAsNull() { $this->assertEquals('NULL', $this->Dbo->value(null, 'date')); $this->assertEquals('NULL', $this->Dbo->value('', 'date')); $this->assertEquals('NULL', $this->Dbo->value('', 'datetime')); $this->assertEquals('NULL', $this->Dbo->value(null, 'datetime')); $this->assertEquals('NULL', $this->Dbo->value('', 'timestamp')); $this->assertEquals('NULL', $this->Dbo->value(null, 'timestamp')); $this->assertEquals('NULL', $this->Dbo->value('', 'time')); $this->assertEquals('NULL', $this->Dbo->value(null, 'time')); }
/** * Returns a quoted and escaped string of $data for use in an SQL statement. * * @param string $data String to be prepared for use in an SQL statement * @param string $column_type The type of the column into which this data will be inserted * @param boolean $safe Whether or not numeric data should be handled automagically if no column data is provided * @return string Quoted and escaped data */ function value($data, $column = null, $safe = false) { $parent = parent::value($data, $column, $safe); if ($parent != null) { return $parent; } if ($data === null) { return 'NULL'; } if ($data === '') { return "''"; } return $this->_adodb->qstr($data); }