如何使用 OTL SELECT 整个表并将其保存到文件?
问题是,我不知道表中的属性有多少个属性或哪种类型,我需要简单的选择语句,例如: SELECT * FROM TABLE1;写入文件。
这需要使用 otlv4 包装器来完成。
请帮忙。
otl_stream i(50, // buffer size
"select * from test_tab where f1>=:f<int> and f1<=:f*2", // SELECT statement
db // connect object
);
int ac=0;
char bc[64];
memset(bc, 0, 64);
while(!i.eof())
{
i >> ac >> bc;
cout << "Boooo " << ac << " " << bc << endl;
}
这是我知道有多少个属性以及有哪些类型的示例。但如果我不知道怎么办?
Here is the problem, I dont know how many attributes or which type are the attributes in table and I need simple select statment like: SELECT * FROM TABLE1; to write down to file.
And this need to be done with otlv4 wrapper.
Please help.
otl_stream i(50, // buffer size
"select * from test_tab where f1>=:f<int> and f1<=:f*2", // SELECT statement
db // connect object
);
int ac=0;
char bc[64];
memset(bc, 0, 64);
while(!i.eof())
{
i >> ac >> bc;
cout << "Boooo " << ac << " " << bc << endl;
}
This is example where I know how many attributes are there and which type are there. But what if I dont know that??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
文件流以及 OTL 的 check_end_of_row() 和 check_end_of_row() 。 sourceforge.net/otl3_stream_class.htm" rel="nofollow">set_all_column_types() 函数应该执行您所要求的操作。在循环 OTL 流的 eof 检查时,对于每一行,您可以循环进行行结束检查,并将每个属性的值从 OTL 流发送到文件流。每次行尾检查后,将换行符代码发送到文件流。将所有列类型设置为 str 应该允许您仅使用一个变量来处理一行中的所有属性值。
OTL 文档中的此示例演示了如何使用 set_all_column_types 函数。您必须先创建流,设置选项,然后打开流。如果您同时创建和打开流,则它将不起作用。
A file stream along with OTL's check_end_of_row() and set_all_column_types() functions should do what you're asking. While looping on an OTL stream's eof check, for each row you could loop on the end of row check, and send each attribute's value from the OTL stream to the file stream. After each end of row check, send your line break code(s) to the file stream. Setting all column types to str should allow you to use just one variable to process all attribute values in a row.
This example from the OTL docs demonstrates how to use the set_all_column_types function. You must create a stream first, set the option, then open the stream. If you create and open the stream at the same time, it won't work.