创建视图:Php->PDO->postgres PDOStatement::execute(): SQLSTATE[42P18]: Indeterminate datatype
creating a view: Php->PDO->postgres PDOStatement::execute(): SQLSTATE[42P18]: Indeterminate datatype
正常 select、插入等工作,现在我无法尝试创建视图并且占位符似乎存在一些问题,如果我插入静态数字而不是占位符,则该行有效。 .. 我先尝试不使用强制转换,然后使用隐式强制转换 (::int),现在是显式强制转换,但它不想工作....
$sql = "CREATE OR REPLACE VIEW allowedlists AS
SELECT distinct l.id, l.nom FROM listing as l,acl,user2acl
WHERE userid=cast(:userid as INTEGER) AND acl.id=aclid
and value > (select value from acl where name='saisie');";
$stmt = $csh->handler->pdo->prepare($sql);
if(!$stmt->bindValue(":userid", $_SESSION["userid"],PDO::PARAM_INT))
print("failed to bind 'userid = ".$_SESSION["userid"]."' as ".PDO::PARAM_INT." to ".print_r($stmt,true)."<br>\n");
else print("bound 'userid' to ".$_SESSION["userid"]." of type '".PDO::PARAM_INT."'<br\n>");
print("before create view<br>\n");
if(!($viewcreation = $stmt->execute()))
{
print("<p style=\"color:red;\">Error: (".$stmt->errorCode()."): ".print_r($stmt->errorInfo(),true)."</p>\n");
$stmt->debugDumpParams();
}
print("after create view<br>\n");
失败:
before create view(1)<br>
<br />
<b>Warning</b>: PDOStatement::execute(): SQLSTATE[42P18]: Indeterminate datatype: 7 ERROR: could not determine data type of parameter in <b>/var/www/html/content/listing.php</b> on line <b>16</b><br />
<p style="color:red;">Error: (42P18): Array
(
[0] => 42P18
[1] => 7
[2] => ERROR: could not determine data type of parameter
)
</p>
SQL: [209] CREATE OR REPLACE VIEW allowedlists AS SELECT distinct l.id, l.nom FROM listing as l,acl,user2acl WHERE userid=cast(:userid as INTEGER) AND acl.id=aclid and value > (select value from acl where name='saisie');
Params: 1
Key: Name: [7] :userid
paramno=0
name=[7] ":userid"
is_param=1
param_type=1
after create view<br>
似乎我在这里遗漏了明显的东西,但我现在把它转了又转了 3 天,但我唯一设法建立的是挫败感?
据我所知,占位符绑定得很好,类型似乎也不错,如前所述,如果我用静态数字替换占位符,它可以工作,但不能与占位符一起使用:(
创建 VIEW 是一个 DDL 操作,类似于创建 table。因此它不能被参数化。然后使用“参数化”它,使用参数是 select 语句的 where 子句。
create or replace view allowedlists as
select distinct l.id, l.nom
from listing as l,acl,user2acl
where acl.id=aclid
and value > (select value from acl where name='saisie');
...
select id, nom
from allowedlists
where id = :userid;
OR
select id, nom
from allowedlists
where id = cast(:userid as integer);
由于 where 子句延迟到 select 从视图中删除,因此可能需要将列添加到 select 创建视图。由于您没有为我无法分辨的所有列添加别名。参数化名称需要类似的方法,但是您的 select
正常 select、插入等工作,现在我无法尝试创建视图并且占位符似乎存在一些问题,如果我插入静态数字而不是占位符,则该行有效。 .. 我先尝试不使用强制转换,然后使用隐式强制转换 (::int),现在是显式强制转换,但它不想工作....
$sql = "CREATE OR REPLACE VIEW allowedlists AS
SELECT distinct l.id, l.nom FROM listing as l,acl,user2acl
WHERE userid=cast(:userid as INTEGER) AND acl.id=aclid
and value > (select value from acl where name='saisie');";
$stmt = $csh->handler->pdo->prepare($sql);
if(!$stmt->bindValue(":userid", $_SESSION["userid"],PDO::PARAM_INT))
print("failed to bind 'userid = ".$_SESSION["userid"]."' as ".PDO::PARAM_INT." to ".print_r($stmt,true)."<br>\n");
else print("bound 'userid' to ".$_SESSION["userid"]." of type '".PDO::PARAM_INT."'<br\n>");
print("before create view<br>\n");
if(!($viewcreation = $stmt->execute()))
{
print("<p style=\"color:red;\">Error: (".$stmt->errorCode()."): ".print_r($stmt->errorInfo(),true)."</p>\n");
$stmt->debugDumpParams();
}
print("after create view<br>\n");
失败:
before create view(1)<br>
<br />
<b>Warning</b>: PDOStatement::execute(): SQLSTATE[42P18]: Indeterminate datatype: 7 ERROR: could not determine data type of parameter in <b>/var/www/html/content/listing.php</b> on line <b>16</b><br />
<p style="color:red;">Error: (42P18): Array
(
[0] => 42P18
[1] => 7
[2] => ERROR: could not determine data type of parameter
)
</p>
SQL: [209] CREATE OR REPLACE VIEW allowedlists AS SELECT distinct l.id, l.nom FROM listing as l,acl,user2acl WHERE userid=cast(:userid as INTEGER) AND acl.id=aclid and value > (select value from acl where name='saisie');
Params: 1
Key: Name: [7] :userid
paramno=0
name=[7] ":userid"
is_param=1
param_type=1
after create view<br>
似乎我在这里遗漏了明显的东西,但我现在把它转了又转了 3 天,但我唯一设法建立的是挫败感?
据我所知,占位符绑定得很好,类型似乎也不错,如前所述,如果我用静态数字替换占位符,它可以工作,但不能与占位符一起使用:(
创建 VIEW 是一个 DDL 操作,类似于创建 table。因此它不能被参数化。然后使用“参数化”它,使用参数是 select 语句的 where 子句。
create or replace view allowedlists as
select distinct l.id, l.nom
from listing as l,acl,user2acl
where acl.id=aclid
and value > (select value from acl where name='saisie');
...
select id, nom
from allowedlists
where id = :userid;
OR
select id, nom
from allowedlists
where id = cast(:userid as integer);
由于 where 子句延迟到 select 从视图中删除,因此可能需要将列添加到 select 创建视图。由于您没有为我无法分辨的所有列添加别名。参数化名称需要类似的方法,但是您的 select