')"; $pos = strpos($data, $str); $tmp = substr($data, 0, $pos + 2); } $data = $tmp; if (isDataUnicode($colType, $data)) { // this includes unicode data type and XML data that is in Unicode // N'data' $data = substr($data, 2, strlen($data) - 3); } elseif (isLiteralType($colType)) { // 'data' $data = substr($data, 1, strlen($data) - 2); } elseif (isBinaryType($colType)) { // 0xdata $data = substr($data, 2); } return (trim($data)); } function isStreamableType($type) { switch ($type) { case _SQL_CHAR: // char return true; case _SQL_WCHAR: // nchar return true; case _SQL_VARCHAR: // varchar return true; case _SQL_WVARCHAR: // nvarchar return true; case _SQL_LONGVARCHAR: // text return true; case _SQL_WLONGVARCHAR: // ntext return true; case _SQL_BINARY: // binary return true; case _SQL_VARBINARY: // varbinary return true; case _SQL_LONGVARBINARY: // image return true; case _SQL_SS_XML: // xml return true; default: break; } return (false); } function isNumericType($type) { switch ($type) { case _SQL_INTEGER: // int return true; case _SQL_TINYINT: // tinyint return true; case _SQL_SMALLINT: // smallint return true; case _SQL_BIGINT: // bigint return true; case _SQL_BIT: // bit return true; case _SQL_FLOAT: // float return true; case _SQL_REAL: // real return true; case _SQL_DECIMAL: // decimal return true; case _SQL_NUMERIC: // numeric, money, smallmoney return true; default: break; } return (false); } function isCharType($type) { switch ($type) { case _SQL_WCHAR: // nchar return true; case _SQL_VARCHAR: // varchar return true; case _SQL_WVARCHAR: // nvarchar return true; case _SQL_LONGVARCHAR: // text return true; case _SQL_WLONGVARCHAR: // ntext return true; case _SQL_SS_XML: // xml return true; default: break; } return (false); } function isBinaryType($type) { switch ($type) { case _SQL_BINARY: // binary return true; case _SQL_VARBINARY: // varbinary return true; case _SQL_LONGVARBINARY: // image return true; default: break; } return (false); } function isDateTimeType($type) { switch ($type) { case _SQL_TYPE_TIMESTAMP: // datetime, smalldatetime return true; case _SQL_TYPE_DATE: // date return true; case _SQL_SS_TIME2: // time return true; case _SQL_SS_TIMESTAMPOFFSET: // datetimeoffset return true; default: break; } return (false); } function isDataUnicode($colType, $data) { if (isUnicodeType($colType)) { return true; } // This input string may be an XML string in unicode (i.e. // N'...') $letterN = 'N'; $index = strpos($data, $letterN); // Note the use of ===. Simply == would not work as expected // because the position of letterN 'N' may be the 0th (first) character // and strpos will return false if not found. if ($index === 0) { return true; } return false; } function isUnicodeType($type) { switch ($type) { case _SQL_WCHAR: // nchar return true; case _SQL_WVARCHAR: // nvarchar return true; case _SQL_WLONGVARCHAR: // ntext return true; default: break; } return (false); } function isXmlType($type) { return ($type == _SQL_SS_XML); } function isColumnUpdatable($colName) { $pos = strpos($colName, "_"); $type = substr($colName, $pos + 1); return (strcasecmp($type, "timestamp") != 0); } function isLiteralType($type) { switch ($type) { case _SQL_CHAR: // char return true; case _SQL_WCHAR: // nchar return true; case _SQL_VARCHAR: // varchar return true; case _SQL_WVARCHAR: // nvarchar return true; case _SQL_LONGVARCHAR: // text return true; case _SQL_WLONGVARCHAR: // ntext return true; case _SQL_GUID: // uniqueidentifier return true; case _SQL_TYPE_TIMESTAMP: // datetime, smalldatetime return true; case _SQL_TYPE_DATE: // date return true; case _SQL_SS_TIME2: // time return true; case _SQL_SS_TIMESTAMPOFFSET: // datetimeoffset return true; case _SQL_SS_XML: // xml return true; default: break; } return (false); }