如何在vb.net中检查查询语法? [英] how to check the query syntax in vb.net?

查看:104
本文介绍了如何在vb.net中检查查询语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,
我在VB.NET 2010中开发了一个查询生成器项目,因为我需要检查输入查询的语法,即,系统应在执行查询之前检查其语法.请任何人给我关于这个想法.

问候,
Sathish

Dear All,
I developing one query Builder project in VB.NET 2010, in that I need to check the input Query''s syntax, ie., the system should check its syntax before the Query has been executed. Please anyone give me the idea about it.

Regards,
Sathish

推荐答案

也许在这里尝试...

SQL解析器 [
Maybe try here...

SQL Parser[^]


亲爱的所有人,
对不起,我忘记指出输入是oracle查询的错误.我创建了一个引用游标,从而创建了一个过程.
此过程的输入参数是我的输入查询,输出参数是作为游标和消息的queryresult.
我所做的是,在try..catch块中,我为我的输入查询打开了此refcursor,如果发生任何语法错误,则在OTHERS条件下将其作为Exception,并将其存储到输出中参数消息.
通过分配SQLERRM函数的结果来完成.

示例代码:

Dear all,
Sorry for the mistake that i forgot to indicate that the input was oracle queries. I''ve created one procedure in that i''ve created one ref cursor.
The input parameter for this procedure was my input query and the output parameters are queryresult as cursor and message.
What i did is, With in the try..catch block, i''ve open this refcursor for my input query and if any syntatic errors occurs which will be Exception under the condition OTHERS, and it''ll be stored to the output parameter message.
It was done by assigning the result of SQLERRM function.

Sample Code:

create or replace PROCEDURE DBP_QUERY_RESULT
       (  
          
          O_QUERY               IN   CLOB,
          O_QRY_RES             OUT  DBK_REPORTS.record_type,
          O_MESSAGE             OUT  VARCHAR2
      )IS
 
V_QUERY            CLOB;
BEGIN
V_QUERY := O_QUERY;
                        
   
      BEGIN
           OPEN O_QRY_RES FOR TO_CHAR(V_QUERY);
          
        EXCEPTION
          WHEN NO_DATA_FOUND THEN
            O_MESSAGE := ''NO RECORDS FOUND'';
          WHEN OTHERS THEN
            O_MESSAGE    := sqlcode || sqlerrm;
                     
       END;
       
                  
END DBP_QUERY_RESULT;


检查语法是什么? SQL Server,MySQL,Oracle或任何其他数据库?每个数据库都有其自己的查询语法,并且IMO没有现成的免费代码可以对数据库查询进行语法检查.您必须编写自己的语法检查库以适合您的需求.一个好的出发点是开始研究如何 SharpDevelop [
Check syntax for what? SQL Server, MySQL, Oracle or any other database? Each database has its own query syntax and IMO there is no ready made free code that does syntax checking for database queries. You have to write your own syntax checking library to suit your needs. A good starting point would be to start digging into how SharpDevelop[^] implements syntax checking for C#. You can study the code and adapt it to make it work for you.


这篇关于如何在vb.net中检查查询语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆