我尝试将GroceryCRUD与SQL Server(2008 R2)一起使用来管理一些表。
好吧,我发现以下线程在StackOverflow上非常有用: How can I run grocery with sql server?
但是,当我使用$this->grocery_crud->set_relation
时,它会返回错误"未找到PrimaryKey"在方法set_primary_key上。
该表显然已正确设置主键。
有人可以帮我找出问题所在吗?
答案 0 :(得分:0)
确定。这就是我破解代码的方式:
ref.version:
第1步
档案: driver = new FirefoxDriver();
string baseurl = "http://localhost:53532";
String ourPath = "~/visual studio 2015";
String testTitle = ourPath + "test.txt";
String testScreenshotTitle = ourPath + "test.jpg";
driver.Navigate().GoToUrl(baseurl);
ITakesScreenshot screenshotDriver = driver as ITakesScreenshot;
Screenshot screenCapture = screenshotDriver.GetScreenshot();
screenCapture.SaveAsFile(testScreenshotTitle, System.Drawing.Imaging.ImageFormat.Jpeg);
更新方法 field_data($ table)
system\database\drivers\pdo\subdrivers\pdo_sqlsrv_driver.php
第2步
档案:public function field_data($table)
{
$sql = 'SELECT c.COLUMN_NAME, c.DATA_TYPE, c.CHARACTER_MAXIMUM_LENGTH, c.NUMERIC_PRECISION, c.COLUMN_DEFAULT
,CASE WHEN pk.COLUMN_NAME IS NOT NULL THEN 1 ELSE 0 END AS KeyType
FROM INFORMATION_SCHEMA.COLUMNS c
LEFT JOIN (
SELECT ku.TABLE_CATALOG,ku.TABLE_SCHEMA,ku.TABLE_NAME,ku.COLUMN_NAME
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS ku
ON tc.CONSTRAINT_TYPE = \'PRIMARY KEY\'
AND tc.CONSTRAINT_NAME = ku.CONSTRAINT_NAME
) pk
ON c.TABLE_CATALOG = pk.TABLE_CATALOG
AND c.TABLE_SCHEMA = pk.TABLE_SCHEMA
AND c.TABLE_NAME = pk.TABLE_NAME
AND c.COLUMN_NAME = pk.COLUMN_NAME
WHERE UPPER(c.TABLE_NAME) = '.$this->escape(strtoupper($table));
if (($query = $this->query($sql)) === FALSE)
{
return FALSE;
}
$query = $query->result_object();
$retval = array();
for ($i = 0, $c = count($query); $i < $c; $i++)
{
$retval[$i] = new stdClass();
$retval[$i]->name = $query[$i]->COLUMN_NAME;
$retval[$i]->type = $query[$i]->DATA_TYPE;
$retval[$i]->max_length = ($query[$i]->CHARACTER_MAXIMUM_LENGTH > 0) ? $query[$i]->CHARACTER_MAXIMUM_LENGTH : $query[$i]->NUMERIC_PRECISION;
$retval[$i]->primary_key = $query[$i]->KeyType;
$retval[$i]->default = $query[$i]->COLUMN_DEFAULT;
}
return $retval;
}
更新方法 field_data($ table)
\system\database\drivers\sqlsrv\sqlsrv_driver.php
第3步
档案:public function field_data($table)
{
$sql = 'SELECT c.COLUMN_NAME, c.DATA_TYPE, c.CHARACTER_MAXIMUM_LENGTH, c.NUMERIC_PRECISION, c.COLUMN_DEFAULT
,CASE WHEN pk.COLUMN_NAME IS NOT NULL THEN 1 ELSE 0 END AS KeyType
FROM INFORMATION_SCHEMA.COLUMNS c
LEFT JOIN (
SELECT ku.TABLE_CATALOG,ku.TABLE_SCHEMA,ku.TABLE_NAME,ku.COLUMN_NAME
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS ku
ON tc.CONSTRAINT_TYPE = \'PRIMARY KEY\'
AND tc.CONSTRAINT_NAME = ku.CONSTRAINT_NAME
) pk
ON c.TABLE_CATALOG = pk.TABLE_CATALOG
AND c.TABLE_SCHEMA = pk.TABLE_SCHEMA
AND c.TABLE_NAME = pk.TABLE_NAME
AND c.COLUMN_NAME = pk.COLUMN_NAME
WHERE UPPER(c.TABLE_NAME) = '.$this->escape(strtoupper($table));
if (($query = $this->query($sql)) === FALSE)
{
return FALSE;
}
$query = $query->result_object();
$retval = array();
for ($i = 0, $c = count($query); $i < $c; $i++)
{
$retval[$i] = new stdClass();
$retval[$i]->name = $query[$i]->COLUMN_NAME;
$retval[$i]->type = $query[$i]->DATA_TYPE;
$retval[$i]->max_length = ($query[$i]->CHARACTER_MAXIMUM_LENGTH > 0) ? $query[$i]->CHARACTER_MAXIMUM_LENGTH : $query[$i]->NUMERIC_PRECISION;
$retval[$i]->primary_key = $query[$i]->KeyType;
$retval[$i]->default = $query[$i]->COLUMN_DEFAULT;
}
return $retval;
}
更新方法 field_data()
\system\database\drivers\mssql\mssql_result.php
这就是全部。我希望它可以帮助其他人。