unixODBC中 column .... does not exist 的解决过程

情况描述:在postgresql中添加表example后,用DTL示范代码访问,提示错误。

dtl代码如下:(添加库odbc、DTL、odbcinst、stdc++)

#include "DTL.h"
#include <iostream>
using namespace dtl;
using namespace std;

int main() {
	cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
	try
	{
			// Connect to the database		DBConnection::GetDefaultConnection().Connect("UID=sa;PWD=123123;DSN=example;");
			// Create a container to hold records from a query.
			// In this case, the query will be "SELECT * FROM DB_EXAMPLE".
			DynamicDBView<> view("DB_EXAMPLE", "*");
			// Read all rows from the database and send to cout
			copy(view.begin(), view.end(), ostream_iterator<variant_row>(cout, "\n"));
	}
	catch (std::exception &ex)
 	{
		// Show any database or other standard errors
		cerr << ex.what() << endl;
	}
	return 0;
}
错误描述如下:

1)在表为空的时候运行程序,提示:

[unixODBC]ERROR:syntax error at or near "FROM";Error while executing the query

2)在表中添加第一个字段INT_VALUE时,在代码中访问,提示如下:

[unixODBC]ERROR:column "int_value"does not exist;


postgresql的官网上也有人提出了同样的问题,不过这个应该不是postgresql的问题,而是DTL的

对于以上两点,各自的解决方法如下:

1)保证表不空

2)字段改为小写,不要出现纯大写或大小写混合

至此,问题解决!



      楼主探索出这个解决方法的过程比较麻烦,一直坚信问题是在postgresql上,因为对系统表则可以成功显示出内容,而用自己建的就不行。

      当时新建了example数据库,example表,结果用最惨重的一次,是删除example表后,sudo -u postgres sh进入了postgres用户新建example表,结果由于这是postgres用户的表,而pgadmin3是用sa用户登录,在图形化窗口中反而删除不了example表,提示permission denies....

      然后又在postgres的shell中加上alternate table example owner to sa;把用户改写,依旧不行。

      最后才发现是大小写的问题,不过依旧掩盖不了DTL的强大啊。话说,postgresql有一个很蛋疼的地方,不添加主键没法往表添加内容,不过有的系统表就没主键,怎么添加的呢?哎

       其实学这些用的人少的东东,有个很不爽的地方就是能参考的中文资料太少(比如linux下的数据库,能找到的绝大部分都是mysql的),所以只能看英文的,虽然英文的也不多,遇到问题的时候,总是很苦恼的,不过解决了这些问题之后,还是很开心的,就这样吧,继续了


       菜鸟go go go ~~~

你可能感兴趣的:(exception,数据库,database,query,PostgreSQL,pgadmin)