它是用于数据库脚本系统()从C的好办法? [英] Is it a good way to use system() for database scripts from C?

查看:107
本文介绍了它是用于数据库脚本系统()从C的好办法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找从C程序连接到数据库。但我以为ODBC连接,登录和都需要一些库。我也是具有最小的编译器像小C编译器,这是非常快的。我不希望使用它需要连接和查询数据库任何ODBC逻辑等。

所以,我使用的是如下的方法。

我用一个脚本BTEQ(Teradata数据),这将有登录,查询,在该注销命令。 (仅供参考BTEQ是一个命令行数据库实用程序,您可以使用它类似于通过进入exe文件的路径在命令提示符下的mysql.exe。你可以等的mysql.exe替换BTEQ)。我用

I was searching for connecting to database from C program. But I thought the ODBC connections, logon and all need some libraries. Also I am having a minimal compiler like Tiny C Compiler which is very fast. I do not want to use any ODBC logic etc which is needed to connect and query the database.

So I am using a method which is as follows.

I use a bteq script (teradata) which will have login, query, logoff commands in that. (FYI bteq is a command line database utility. You can use it similar to mysql.exe in command prompt by going to the path of the exe. You can replace bteq with mysql.exe etc). And I use

system("bteq <myscript.txt >out.txt");

myscript.txt会像下面的。

myscript.txt will be like the following..

.logon boxname/user,password;
select date;
.logoff;

以上脚本将登录到数据库和查询日期(您可以更改查询,并根据您的数据库引擎和需求编写脚本),并给输出到out.txt。

现在我将解析该行x的列我想用龟etc,或者的fscanf的与fgets out.txt。
并使用数据进行检查和任何服务器上发送使用PHP邮件


系统(C:/server/php/php.exe sendmail.php);

我们可以为许多数据库引擎,如MySQL,..等通过一个简单的C程序这样做。

现在我的问题是有没有在上述方法中的任何缺陷。
如果它是那么我怎样才能克服它。我问这个问题,因为我觉得这个方法是标新立异。请给你对这个方法的意见。我没有理会需要执行时间,RAM使用,性能问题等。我知道system()函数是费时这不是我关心的反正。我还开发了特定的功能来访问查询结果(类似于访问一个平面文件)。请告诉我,如果你有这种方法的任何改进。如果你了解了任何缺陷请让我知道。各种建议,欢迎。

我的环境是:与微小的C编译器窗口的Teradata BTEQ

The above script will logon to the database and query date (you can change the query and write script according to your database engine and your needs) and give output into out.txt.

Now I will parse the out.txt for the row X column I want using fgetc,fscanf or fgets. And use the data for checking and send a mail using PHP on any server

system("c:/server/php/php.exe sendmail.php");.

We can do the same for many a database engines like mysql, .. etc through a simple C program.

Now my question is Is there any flaw in the above method. If it is then how can I overcome it. I am asking this question because I think this method is unconventional. Please give your opinions on this method. I don't bother about time needed for execution, RAM used, performance issues etc. I know system() function is time consuming which is not my concern anyway. I also developed specific functions to access query results (similar to accessing a flat file). Please tell me if you have any improvements to this method. If you get to know of any flaws in this please let me know. All kinds of suggestions are welcome.

My environment is : teradata bteq on windows with Tiny C Compiler

推荐答案

该方法是好的。这是伟大的通过在适当的语言实现他们分离数据库子系统和分析器子系统

The method is fine: it's great to decouple the db subsystem and the parser subsystem by implementing them in an appropriate language.

有只是这个微小的小东西 - 但我可能是错误的,因为我不熟悉BTEQ:程序需要安装在执行文件夹中的BTEQ脚本;该脚本将包含用户名和密码。如果这些不以某种方式encripted,有可能是一个安全漏洞。

There's just this tiny little thing - but I may be mistaken because I'm not familiar with bteq: the program will need a bteq script installed in the execution folder; this script will contain username and password. If those aren't encripted in some way, there might be a security flaw.

这篇关于它是用于数据库脚本系统()从C的好办法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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