* @author Alan Knowles <alan@akbkhome.com>
* @copyright 1997-2008 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version CVS: $Id: Cast.php 287158 2009-08-12 13:58:31Z alan_k $
+ * @version CVS: $Id: Cast.php 326604 2012-07-12 03:02:00Z alan_k $
* @link http://pear.php.net/package/DB_DataObject
*/
// this is funny - the parameter order is reversed ;)
return "'".sqlite_escape_string($this->value)."'";
+ case 'mssql':
+
+ if(is_numeric($this->value)) {
+ return $this->value;
+ }
+ $unpacked = unpack('H*hex', $this->value);
+ return '0x' . $unpacked['hex'];
+
+
default:
return PEAR::raiseError("DB_DataObject_Cast cant handle blobs for Database:{$db->dsn['phptype']} Yet");
}
// perhaps we should support TEXT fields???
//
- if (!($to & DB_DATAOBJECT_BLOB)) {
- return PEAR::raiseError('Invalid Cast from a DB_DataObject_Cast::string to something other than a blob!'.
- ' (why not just use native features)');
- }
+ // $to == a string field which is the default type (0)
+ // so we do not test it here. - we assume that number fields
+ // will accept a string?? - which is stretching it a bit ...
+ // should probaly add that test as some point.
switch ($db->dsn['phptype']) {
case 'pgsql':
case 'mysqli':
return "'".mysqli_real_escape_string($db->connection, $this->value)."'";
-
+ case 'mssql':
+ // copied from the old DB mssql code...?? not sure how safe this is.
+ return "'" . str_replace(
+ array("'", "\\\r\n", "\\\n"),
+ array("''", "\\\\\r\n\r\n", "\\\\\n\n"),
+ $this->value
+ ) . "'";
+
+
default:
return PEAR::raiseError("DB_DataObject_Cast cant handle blobs for Database:{$db->dsn['phptype']} Yet");
}
-
}