added full-text search tests
This commit is contained in:
parent
2fcff55432
commit
a6ce2be894
128
test/pdo_sqlsrv/issue_52_pdo.phpt
Normal file
128
test/pdo_sqlsrv/issue_52_pdo.phpt
Normal file
|
@ -0,0 +1,128 @@
|
|||
--TEST--
|
||||
verify github issue52 is fixed.
|
||||
--DESCRIPTION--
|
||||
This test only works in previous versions of SQL Servers. Full-text search features are
|
||||
deprecated starting in SQL Server 2016.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once 'MsCommon.inc';
|
||||
require_once 'MsSetup.inc';
|
||||
|
||||
$conn = new PDO( "sqlsrv:server=$server;database=$databaseName", $uid, $pwd);
|
||||
|
||||
#=================check SQL Server version===============
|
||||
$attr = $conn->getAttribute(constant('PDO::ATTR_SERVER_VERSION'));
|
||||
$version = substr($attr, 0, 2);
|
||||
if ($version >= 13)
|
||||
{
|
||||
echo "Full-text search feature deprecated.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
#=================run the test===========================
|
||||
$tableName = 'test_Fulltext';
|
||||
$dataType = 'Pagename varchar(20) not null primary key,URL varchar(30) not null,Description text null,Keywords varchar(4000) null';
|
||||
|
||||
if($conn)
|
||||
{
|
||||
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
echo "Connection established.<br/>";
|
||||
CreateTableEx($conn, $tableName, $dataType);
|
||||
PopulateTable($conn,$tableName);
|
||||
EnableFullText($conn, $tableName);
|
||||
checkActiveTransactions($conn);
|
||||
sleep(5);
|
||||
FetchData($conn, $tableName);
|
||||
DisableFullText($conn,$tableName);
|
||||
FetchData($conn,$tableName);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Connection could not be established.\n";
|
||||
}
|
||||
#=======================================================
|
||||
function FetchData($conn,$tableName){
|
||||
$query = "SELECT * FROM $tableName WHERE freetext(description,'Magazine')";
|
||||
$stmt = $conn->query($query);
|
||||
if(!$stmt)
|
||||
{
|
||||
var_dump($conn->errorInfo());
|
||||
die( "PDOConn->query failed");
|
||||
}
|
||||
|
||||
$stmt->bindColumn('Pagename',$Pagename);
|
||||
$stmt->bindColumn('URL',$URL);
|
||||
$stmt->bindColumn('Description',$Description);
|
||||
$stmt->bindColumn('Keywords',$Keywords);
|
||||
$result = $stmt->fetch(PDO::FETCH_BOUND);
|
||||
if(!$result)
|
||||
{
|
||||
die("Fetch failed");
|
||||
}
|
||||
echo $Pagename . "\n";
|
||||
echo $URL . "\n";
|
||||
echo $Description . "\n";
|
||||
}
|
||||
|
||||
#creating dummy data
|
||||
function PopulateTable($conn,$tableName){
|
||||
$dataCols = 'Pagename,URL,Description,Keywords';
|
||||
$row1 = "'home.asp','home.asp','This is the home page','home,SQL'";
|
||||
$row2 = "'PAGETWO.asp','/page2/pagetwo.asp','NT Magazine is great','second'";
|
||||
$row3 = "'pagethree.asp','/page3/pagethree.asp','SQL Magazine is the greatest','third'";
|
||||
$dataValues = array($row1, $row2, $row3);
|
||||
foreach($dataValues as $value)
|
||||
{
|
||||
InsertRowEx($conn, $tableName, $dataCols, $value, null);
|
||||
}
|
||||
}
|
||||
|
||||
function EnableFullText($conn,$tableName){
|
||||
echo "Enabling full-text index ... ";
|
||||
$catalogName = "fulltext_".$tableName."_catalog";
|
||||
#if the fulltext catalog exists, drop it;
|
||||
dropCatalog($conn, $catalogName);
|
||||
$query = "CREATE UNIQUE INDEX ui_ukJobCand ON $tableName(Pagename); CREATE FULLTEXT CATALOG $catalogName as default; CREATE FULLTEXT INDEX ON $tableName(URL, Description, Keywords) KEY INDEX ui_ukJobCand with stoplist = SYSTEM";
|
||||
$outcome = $conn->exec($query);
|
||||
if($outcome === false){
|
||||
die("Failed to enable FULLTEXT INDEX on $tableName");
|
||||
}
|
||||
echo "completed successfully.\n";
|
||||
}
|
||||
|
||||
function DisableFullText($conn,$tableName){
|
||||
echo "\n Disabling full-text index ... ";
|
||||
$query = "DROP FULLTEXT INDEX ON $tableName";
|
||||
$outcome = $conn->exec($query);
|
||||
if($outcome === false){
|
||||
die("Failed to drop the FULLTEXT INDEX on $tableName");
|
||||
}
|
||||
echo "completed successfully.\n";
|
||||
}
|
||||
#=====================helpers==========================
|
||||
function dropCatalog($conn, $catalogName){
|
||||
$catalogExists="IF EXISTS (SELECT 1 FROM sys.fulltext_catalogs WHERE [name] = '$catalogName')
|
||||
DROP FULLTEXT CATALOG $catalogName";
|
||||
$outcome = $conn->exec($catalogExists);
|
||||
if($outcome === false){
|
||||
die("Failed to drop the $catalogName");
|
||||
}
|
||||
}
|
||||
|
||||
function checkActiveTransactions($conn){
|
||||
$isActive = $conn->inTransaction();
|
||||
if(!$isActive){
|
||||
echo "No active transactions within the driver.\n";
|
||||
}else{
|
||||
echo "A transaction is currently active.\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
--EXPECTREGEX--
|
||||
(Full-text search feature deprecated.|.*Connection established(.*Magazine.*)*
|
||||
.*Disabling full-text index ... completed successfully..*
|
||||
.*["message"].*Cannot use a CONTAINS or FREETEXT predicate on table or indexed view.* not full-text indexed.*)
|
122
test/sqlsrv/issue_52.phpt
Normal file
122
test/sqlsrv/issue_52.phpt
Normal file
|
@ -0,0 +1,122 @@
|
|||
--TEST--
|
||||
verify github issue52 is fixed.
|
||||
--DESCRIPTION--
|
||||
This test only works in previous versions of SQL Servers. Full-text search features are
|
||||
deprecated starting in SQL Server 2016.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
|
||||
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
|
||||
require_once 'MsCommon.inc';
|
||||
|
||||
$conn = Connect();
|
||||
|
||||
$server_info = sqlsrv_server_info( $conn);
|
||||
if( $server_info )
|
||||
{
|
||||
// check SQL Server version
|
||||
$version = substr($server_info['SQLServerVersion'], 0, 2);
|
||||
if ($version >= 13)
|
||||
{
|
||||
echo "Full-text search feature deprecated.\n";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$tableName = 'test_Fulltext';
|
||||
$dataType = 'Pagename varchar(20) not null primary key,URL varchar(30) not null,Description text null,Keywords varchar(4000) null';
|
||||
#===================================
|
||||
if($conn)
|
||||
{
|
||||
echo "Connection established.<br/>";
|
||||
CreateTableEx($conn, $tableName, $dataType);
|
||||
PopulateTable($conn,$tableName);
|
||||
EnableFullText($conn, $tableName);
|
||||
sleep(5);
|
||||
FetchData($conn, $tableName);
|
||||
DisableFullText($conn,$tableName);
|
||||
FetchData($conn,$tableName);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Connection could not be established.\n";
|
||||
die(print_r(sqlsrv_errors(),true));
|
||||
}
|
||||
|
||||
sqlsrv_close($conn);
|
||||
#====================================================================
|
||||
function FetchData($conn, $tableName){
|
||||
$query = "SELECT * FROM $tableName WHERE freetext(description,'Magazine')";
|
||||
$rtn_qry = sqlsrv_query($conn,$query);
|
||||
if(!$rtn_qry)
|
||||
{
|
||||
var_dump( sqlsrv_errors() );
|
||||
die( "sqlsrv_query(6) failed." );
|
||||
}
|
||||
while(sqlsrv_fetch($rtn_qry))
|
||||
{
|
||||
|
||||
$id = sqlsrv_get_field( $rtn_qry, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
|
||||
echo "$id <br/>";
|
||||
$id1 = sqlsrv_get_field( $rtn_qry, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
|
||||
echo "$id1 <br/>";
|
||||
$id2 = sqlsrv_get_field( $rtn_qry, 2, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
|
||||
echo "$id2 <br/>";
|
||||
$id3 = sqlsrv_get_field( $rtn_qry, 3, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
|
||||
echo "$id3 <br/>";
|
||||
}
|
||||
}
|
||||
|
||||
function PopulateTable($conn,$tableName){
|
||||
$dataCols = 'Pagename,URL,Description,Keywords';
|
||||
$row1 = "'home.asp','home.asp','This is the home page','home,SQL'";
|
||||
$row2 = "'PAGETWO.asp','/page2/pagetwo.asp','NT Magazine is great','second'";
|
||||
$row3 = "'pagethree.asp','/page3/pagethree.asp','SQL Magazine is the greatest','third'";
|
||||
$dataValues = array($row1, $row2, $row3);
|
||||
foreach($dataValues as $value)
|
||||
{
|
||||
InsertRowEx($conn, $tableName, $dataCols, $value, null);
|
||||
}
|
||||
}
|
||||
|
||||
function EnableFullText($conn,$tableName){
|
||||
|
||||
echo "Enabling full-text index ... ";
|
||||
$catalogName = "fulltext_".$tableName."_catalog";
|
||||
#if the fulltext catalog exists, drop it;
|
||||
dropCatalog($conn, $catalogName);
|
||||
$sql = $query = "CREATE UNIQUE INDEX ui_ukJobCand ON $tableName(Pagename); CREATE FULLTEXT CATALOG $catalogName as default; CREATE FULLTEXT INDEX ON $tableName(URL, Description, Keywords) KEY INDEX ui_ukJobCand with stoplist = SYSTEM";
|
||||
$outcome = sqlsrv_query($conn, $sql);
|
||||
if(!$outcome){
|
||||
die("Failed to enable FULLTEXT INDEX on $tableName");
|
||||
}
|
||||
echo "completed successfully.\n";
|
||||
}
|
||||
|
||||
function DisableFullText($conn,$tableName){
|
||||
echo "\n Disabling full-text index ... ";
|
||||
$sql = "DROP FULLTEXT INDEX ON $tableName";
|
||||
$outcome = sqlsrv_query($conn, $sql);
|
||||
if(!$outcome){
|
||||
die("Failed to drop the FULLTEXT INDEX on $tableName");
|
||||
}
|
||||
echo "completed successfully.\n";
|
||||
}
|
||||
#================helpers=====================
|
||||
function dropCatalog($conn, $catalogName){
|
||||
$catalogExists="IF EXISTS (SELECT 1 FROM sys.fulltext_catalogs WHERE [name] = '$catalogName')
|
||||
DROP FULLTEXT CATALOG $catalogName";
|
||||
$outcome = sqlsrv_query($conn, $catalogExists);
|
||||
if(!$outcome){
|
||||
die("Failed to drop the $catalogName");
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
--EXPECTREGEX--
|
||||
(Full-text search feature deprecated.|.*Connection established(.*Magazine.*)*
|
||||
.*Disabling full-text index ... completed successfully..*
|
||||
.*["message"].*Cannot use a CONTAINS or FREETEXT predicate on table or indexed view.* not full-text indexed.*)
|
|
@ -16,9 +16,10 @@ sqlsrv_configure('LogSubsystems', 15); // True
|
|||
|
||||
require( 'MsCommon.inc' );
|
||||
|
||||
$conn = Connect();
|
||||
$conn = ConnectUTF8();
|
||||
|
||||
$field_type = 'NVARCHAR(4000)';
|
||||
echo "Testing output type: NVARCHAR(4000)\n";
|
||||
|
||||
$stmt = sqlsrv_query($conn, "DROP PROC [TestFullLenStringsOut]");
|
||||
$stmt = sqlsrv_query($conn, "CREATE PROC [TestFullLenStringsOut] (@p1 " . $field_type . ", @p2 " . $field_type . " OUTPUT)
|
||||
|
@ -49,6 +50,7 @@ if ($str != 'AA')
|
|||
|
||||
$field_type = 'VARCHAR(8000)';
|
||||
$inValue1 = str_repeat( "A", 7999 );
|
||||
echo "Testing output type: VARCHAR(8000)\n";
|
||||
|
||||
$stmt = sqlsrv_query($conn, "DROP PROC [TestFullLenStringsOut]");
|
||||
if( $stmt === false ) {
|
||||
|
@ -80,6 +82,7 @@ if ($str != 'AA')
|
|||
|
||||
$field_type = 'VARBINARY(8000)';
|
||||
$inValue1 = str_repeat( "A", 7999 );
|
||||
echo "Testing output type: VARBINARY(8000)\n";
|
||||
|
||||
$stmt = sqlsrv_query($conn, "DROP PROC [TestFullLenStringsOut]");
|
||||
if( $stmt === false ) {
|
||||
|
@ -116,4 +119,7 @@ sqlsrv_close( $conn ); // True
|
|||
|
||||
?>
|
||||
--EXPECT--
|
||||
Testing output type: NVARCHAR(4000)
|
||||
Testing output type: VARCHAR(8000)
|
||||
Testing output type: VARBINARY(8000)
|
||||
Test complete.
|
Loading…
Reference in a new issue