识别在运行时在Delphi TQuery中使用的用户定义的sql的参数类型

时间:2021-07-11 17:36:25

I'm writing a delphi(7 ver) application and in some place I want to execute parameterized queries (for BDE and Paradox) which will be loaded at runtime into a TQuery by the user. These queries will be stored in text files (one text file for one query). The application then, will construct for any parameter of the query, one input control (Tedit) in order to be able to accept values by the user. Also there will be a button for the execution of query. My question is how can I recognize the datatype of the query's parameter? Is there a way to get this type without of cause to be included in some way in the text file containing the query?

我正在编写一个delphi(7 ver)应用程序,在某些地方我想执行参数化查询(对于BDE和Paradox),这些查询将在运行时由用户加载到TQuery中。这些查询将存储在文本文件中(一个查询的一个文本文件)。然后,应用程序将构造查询的任何参数,一个输入控件(Tedit),以便能够接受用户的值。还会有一个执行查询的按钮。我的问题是如何识别查询参数的数据类型?是否有办法在没有原因的情况下将此类型以某种方式包含在包含查询的文本文件中?

3 个解决方案

#1


0  

  1. Create a second query from the first, but modify its where clause to ensure no rows.

    从第一个查询创建第二个查询,但修改其where子句以确保没有行。

    SELECT * FROM MYTABLE WHERE PKFIELD IS NULL

    SELECT * FROM MYTABLE,其中PKFIELD为NULL

  2. Name your parameters so that you can establish their datatypes from the fieldtypes of this second query.

    为参数命名,以便可以从第二个查询的字段类型中建立其数据类型。

I realise this only works for relatively simple cases, but it should get you some of the way.

我意识到这只适用于相对简单的情况,但它应该让你有所作为。

#2


0  

the advantage of using a parameter is that you don't need to know its data type. Use the string value from the tedit "select * from mytable where myfield = :param1" "parambyname('param1').asstring := edit1.text"

使用参数的优点是您不需要知道其数据类型。使用tedit中的字符串值“select * from mytable where myfield =:param1”“parambyname('param1')。asstring:= edit1.text”

#3


-1  

I've made this with MySQL database. you must define some parameters, Exemple: SELECT * FROM MyTable WHERE MyField=[ANNEE]; in this case, i have an other table, called balise, that look like this

我用MySQL数据库做了这个。你必须定义一些参数,例如:SELECT * FROM MyTable WHERE MyField = [ANNEE];在这种情况下,我有另一张名为balise的表,看起来像这样

"ID" "BALISE" "CAPTION" "DEFAULT_VALUE" "CNDT" "COMPOSANT" "1" "ANNEE" "Année" "2014" "Properties.MaxValue=2014||Properties.MinValue=2007" 1;

“ID”“BALISE”“CAPTION”“DEFAULT_VALUE”“CNDT”“COMPOSANT”“1”“ANNEE”“Année”“2014”“Properties.MaxValue = 2014 || Properties.MinValue = 2007”1;

in runtime, this mean that: Make in my Panel, a TLablel that have caption Année Make in the same line an other component type 1 (That mean in my case TcxSpinEdit), this component have défault value 2014, have Two properties Max Value=2014 and Min Value=2007, (I use RTTI to modifie this value of parameters, in Delphi ver7, use TypeInfo).

在运行时,这意味着:在我的Panel中创建一个TLablel,其中有标题AnnéeMake在同一行中另一个组件类型1(这意味着在我的情况下为TcxSpinEdit),此组件具有défault值2014,具有两个属性Max Value = 2014和Min Value = 2007,(我使用RTTI来修改这个参数值,在Delphi ver7中,使用TypeInfo)。

An Other Button with function called Actualise, this function have Original query, must browse an array of TBalise that i have created, take the value (In my case, take TcxSpinEdit(MyObject).Value), and replace it in the copy of my query (AnsiReplaceStr(Requete, '[ANNEE]', MyValue)), so i have the final query to execute it.

一个名为Actualize的函数的其他按钮,这个函数有原始查询,必须浏览我创建的TBalise数组,取值(在我的情况下,取TcxSpinEdit(MyObject).Value),并将其替换为我的副本查询(AnsiReplaceStr(Requete,'[ANNEE]',MyValue)),所以我有最后的查询来执行它。

I have module in complete projet, worked with this methode, and it workk fine.

我有完整项目的模块,使用这种方法,它工作得很好。

#1


0  

  1. Create a second query from the first, but modify its where clause to ensure no rows.

    从第一个查询创建第二个查询,但修改其where子句以确保没有行。

    SELECT * FROM MYTABLE WHERE PKFIELD IS NULL

    SELECT * FROM MYTABLE,其中PKFIELD为NULL

  2. Name your parameters so that you can establish their datatypes from the fieldtypes of this second query.

    为参数命名,以便可以从第二个查询的字段类型中建立其数据类型。

I realise this only works for relatively simple cases, but it should get you some of the way.

我意识到这只适用于相对简单的情况,但它应该让你有所作为。

#2


0  

the advantage of using a parameter is that you don't need to know its data type. Use the string value from the tedit "select * from mytable where myfield = :param1" "parambyname('param1').asstring := edit1.text"

使用参数的优点是您不需要知道其数据类型。使用tedit中的字符串值“select * from mytable where myfield =:param1”“parambyname('param1')。asstring:= edit1.text”

#3


-1  

I've made this with MySQL database. you must define some parameters, Exemple: SELECT * FROM MyTable WHERE MyField=[ANNEE]; in this case, i have an other table, called balise, that look like this

我用MySQL数据库做了这个。你必须定义一些参数,例如:SELECT * FROM MyTable WHERE MyField = [ANNEE];在这种情况下,我有另一张名为balise的表,看起来像这样

"ID" "BALISE" "CAPTION" "DEFAULT_VALUE" "CNDT" "COMPOSANT" "1" "ANNEE" "Année" "2014" "Properties.MaxValue=2014||Properties.MinValue=2007" 1;

“ID”“BALISE”“CAPTION”“DEFAULT_VALUE”“CNDT”“COMPOSANT”“1”“ANNEE”“Année”“2014”“Properties.MaxValue = 2014 || Properties.MinValue = 2007”1;

in runtime, this mean that: Make in my Panel, a TLablel that have caption Année Make in the same line an other component type 1 (That mean in my case TcxSpinEdit), this component have défault value 2014, have Two properties Max Value=2014 and Min Value=2007, (I use RTTI to modifie this value of parameters, in Delphi ver7, use TypeInfo).

在运行时,这意味着:在我的Panel中创建一个TLablel,其中有标题AnnéeMake在同一行中另一个组件类型1(这意味着在我的情况下为TcxSpinEdit),此组件具有défault值2014,具有两个属性Max Value = 2014和Min Value = 2007,(我使用RTTI来修改这个参数值,在Delphi ver7中,使用TypeInfo)。

An Other Button with function called Actualise, this function have Original query, must browse an array of TBalise that i have created, take the value (In my case, take TcxSpinEdit(MyObject).Value), and replace it in the copy of my query (AnsiReplaceStr(Requete, '[ANNEE]', MyValue)), so i have the final query to execute it.

一个名为Actualize的函数的其他按钮,这个函数有原始查询,必须浏览我创建的TBalise数组,取值(在我的情况下,取TcxSpinEdit(MyObject).Value),并将其替换为我的副本查询(AnsiReplaceStr(Requete,'[ANNEE]',MyValue)),所以我有最后的查询来执行它。

I have module in complete projet, worked with this methode, and it workk fine.

我有完整项目的模块,使用这种方法,它工作得很好。