简体   繁体   English

“ where子句”中的未知列“ x”

[英]Unknown column 'x' in 'where clause'

I'm using MySql , Delphi. 我正在使用MySql和Delphi。 What's my wrong at below code ?? 下面的代码我怎么了?

I get "Unknown Column 'x' in where clause" Error --> Unknown column '_code_ehda_konandeh' in 'where clause' I so need it. 我在“ where子句”中收到“未知列'x'”错误->在'where子句'中未知列'_code_ehda_konandeh'我因此需要它。 i have to do this proj for 2 days later please........ 我必须做这个项目2天后........


   DELIMITER $$

USE `bimarestan`$$

DROP PROCEDURE IF EXISTS `Save_Ehda_Konande`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `Save_Ehda_Konande`(
IN _code_ehda_konandeh VARCHAR(50),
IN _tarikh_moarefi VARCHAR(50),
IN _tarikh_tashkil_parvandeh VARCHAR(50),
IN _name VARCHAR(50),
IN _name_khanevadegi VARCHAR(50),
IN _name_pedar VARCHAR(50),
IN _tarikh_tavalod VARCHAR(20),
IN _tahsilat VARCHAR(50),
IN _vaziyat_taahol VARCHAR(50),
IN _noe_bimeh VARCHAR(50),
IN _gorooh_khoon VARCHAR(50),
IN _rezayat_dahandeh VARCHAR(50),
IN _shoghl VARCHAR(50),
IN _address VARCHAR(50),
IN _telphone VARCHAR(50),
OUT _out INT)
BEGIN
IF LTRIM(RTRIM(_code_ehda_konandeh))<>'' THEN
 BEGIN
 SET _out = 0;
  IF NOT EXISTS(SELECT * FROM bimar WHERE `_code_ehda_konandeh` = `code_ehda_konandeh`) THEN
    INSERT INTO `ehda_konandeh` (
code_ehda_konandeh,
tarikh_moarefi,
tarikh_tashkil_parvandeh,
NAME,
name_khanevadegi,
name_pedar,
tarikh_tavalod,
tahsilat,
vaziyat_taahol,
noe_bimeh,
gorooh_khoon,
rezayat_dahandeh,
shoghl,
address,
telphone)
    VALUES(
_code_ehda_konandeh,
_tarikh_moarefi,
_tarikh_tashkil_parvandeh,
_name,
_name_khanevadegi,
_name_pedar,
_tarikh_tavalod,
_tahsilat,
_vaziyat_taahol,
_noe_bimeh,
_gorooh_khoon,
_rezayat_dahandeh,
_shoghl,
_address,
_telphone
);
  ELSE
    SET _out = 1;  
  END IF;
    END; 
END IF;
END$$

DELIMITER ;

that Stored Proc Run at MySql Without any problems but when i want send delphi parameters to that, i get that error!! 在MySql上存储的Proc运行没有任何问题,但是当我想向其发送delphi参数时,我得到了该错误!

and this is my delphi code : 这是我的delphi代码:

if flag_new_edit = 1 then
  sp_sabt.StoredProcName := 'Save_Ehda_Konande'
 else
  sp_sabt.StoredProcName := 'Edit_Ehda_Konande';
   With sp_sabt Do
   Begin
   ParamByName('_code_ehda_konandeh').Value := Trim(txt_code_ehda_konande.Text);
   ParamByName('_tarikh_moarefi').Value := Trim(txt_tarikh_tavalod.Text);
   ParamByName('_tarikh_tashkil_parvandeh').Value := Trim(txt_name_khanevadegi.Text);
   ParamByName('_name').Value := Trim(txt_name.Text);
   ParamByName('_name_khanevadegi').Value := Trim(txt_name_khanevadegi.Text);
   ParamByName('_name_pedar').Value := Trim(txt_name_pedar.Text);
   ParamByName('_tarikh_tavalod').Value := Trim(txt_tarikh_tavalod.Text);
   ParamByName('_tahsilat').Value := Trim(cmb_tahsilat.Text);
   ParamByName('_vaziyat_taahol').Value := Trim(cmb_vaziyat_taahol.Text);
   ParamByName('_noe_bimeh').Value := Trim(cmb_noe_bime.Text);
   ParamByName('_gorooh_khoon').Value := Trim(cmb_gorooh_khoon.Text);
   ParamByName('_rezayat_dahandeh').Value := Trim(txt_rezayat_dahande.Text);
   ParamByName('_shoghl').Value := Trim(txt_shoghl.Text);
   ParamByName('_address').Value := Trim(txt_adress.Text);
   ParamByName('_telphone').Value := Trim(txt_tel.Text);
   ExecProc;
End;

Regards 问候

  IF NOT EXISTS(SELECT * FROM bimar WHERE `_code_ehda_konandeh` = `code_ehda_konandeh`) THEN
                                          ^---                ^---

remove the indicated quotes. 删除指示的引号。 backticks are used to "escape" reserved words. 反引号用于“转义”保留字。 They also force MySQL to treat those escaped words as field/table names. 它们还强制MySQL将那些转义的单词视为字段/表名。 Your parameters are not fields, so MySQL's being forced to misinterpret them as such. 您的参数不是字段,因此MySQL被迫错误地解释它们。

Though I pointed out what the error could be in your sql code, I would like to give more details on it. 尽管我指出了您的sql代码中的错误,但我想提供更多详细信息。

That Stored Procedure Runing at MySql WithOut any problems but when send Delphi parameters to sp , i get that Error !! But you are wrong. 但是你错了。

There is a known bug in your procedure creation. 您的过程创建中存在a known bug Due to the reason a runtime exception was raised . 由于该原因,引发运行时异常
Semantics of Stored procedure code is not checked at CREATE time. At runtime, undeclared variables are detected, and an error message is generated for each reference to an undeclared variable. However, SP's seem to believe any reference denotes a column, even though the syntactic context excludes that. This leads to a very confusing error message in case the procedure.

A standard test example is as shown below: 标准测试示例如下所示:

mysql> drop procedure proc_test;
Query OK, 0 rows affected (0.00 sec)

mysql> delimiter //
mysql> CREATE PROCEDURE proc_test()
    -> BEGIN
    ->     select current_day;
    -> END
    -> //
Query OK, 0 rows affected (0.00 sec)

Here you can understand that procedure compilation ignored on what current day is. 在这里,您可以了解current day被忽略的过程编译。

mysql> delimiter ;
mysql> call proc_test();
ERROR 1054 (42S22): Unknown column 'current_day' in 'field list'
mysql>

With this you should understand that That Stored Procedure Runing at MySql WithOut any problems ... is not correct. 有了这个,您应该理解That Stored Procedure Runing at MySql WithOut any problems ...而没有That Stored Procedure Runing at MySql WithOut any problems ...是不正确的。


A quick fix to your query will resolve the issue. 快速解决您的查询将解决此问题。 You mentioned that I defined input parameters with _ prefix. I don't know waht i must do ! 您提到I defined input parameters with _ prefix. I don't know waht i must do ! I defined input parameters with _ prefix. I don't know waht i must do ! . If that is true, then 如果是这样的话
change 更改

SELECT * FROM bimar WHERE `_code_ehda_konandeh` = `code_ehda_konandeh`

to

SELECT * FROM bimar WHERE `code_ehda_konandeh` = _code_ehda_konandeh

and it should be working. 它应该正在工作。 Here I assumed code_ehda_konandeh is a column of table bimar too. 在这里,我还假定code_ehda_konandeh也是表bimar一列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM