📄 rdbaces.h
字号:
#ifndef _GET_ALL_REC_H#define _GET_ALL_REC_H#include "opt_include.h"#include <vector>#include <string>using namespace std;/*按域名或域号从实时库中取设备所有记录模版。模板参数包括使用本地接口还是网络接口。分别提供了将应用号和表号放在模版和函数参数中的接口。返回数据有三种: CBuffer、const结构指针、vector。返回值:int >=0 获得的记录数,<0 错误。*/template<class DB_MODE>int GetAllRec( int app_no, int table_id,string field_name, CBuffer &get_result){ static DB_MODE table; table.Open(app_no, table_id); return table.TableGet(field_name.c_str(), get_result);}template<class DB_MODE>int GetAllRec(int app_no, int table_id,vector<int> column_id_vec, CBuffer &get_result){ static DB_MODE table; table.Open(app_no, table_id); return table.TableGet(column_id_vec, get_result);}template<class DB_MODE, class DATA_STRUCT>int GetAllRec(int app_no, int table_id,string field_name, const DATA_STRUCT *buffer_ptr){ CBuffer get_result; int rec_num = GetAllRec<DB_MODE>(app_no,table_id,field_name, get_result); if(rec_num >= 0) { get_result.Detach(); buffer_ptr = (const DATA_STRUCT*)get_result.GetBufPtr(); return rec_num; } else { return -1; }}template<class DB_MODE, class DATA_STRUCT>int GetAllRec(int app_no, int table_id,string field_name, vector<DATA_STRUCT> &result_vec){ CBuffer get_result; int rec_num = GetAllRec<DB_MODE>(app_no, table_id,field_name, get_result);// printf("rec_num==%d\n",rec_num); if(rec_num >= 0) {// printf("get_result.GetLength()==%d,sizeof(DATA_STRUCT)==%d\n",get_result.GetLength(),sizeof(DATA_STRUCT)); result_vec.assign((DATA_STRUCT*)get_result.GetBufPtr(), (DATA_STRUCT*)get_result.GetBufPtr() + get_result.GetLength()/sizeof(DATA_STRUCT)); return result_vec.size(); } else { return -1; }}template<class DB_MODE , class DATA_STRUCT>int FindByKey(int app_no,int table_id,int rec_id, string field_name,DATA_STRUCT & result){ static DB_MODE table; table.Open(app_no, table_id); return table.TableGetByKey((char *)&rec_id,field_name.c_str(),(char *)&result,sizeof(DATA_STRUCT));}template<class DB_MODE , class DATA_STRUCT>int ConFindByKey(int app_no,int table_id,string sql_str,vector<DATA_STRUCT> & result_vec){ static DB_MODE table; CBuffer get_result; int rec_num; table.Open(app_no, table_id); rec_num=table.SqlGet(sql_str.c_str(), get_result); if(rec_num > 0) { result_vec.assign((DATA_STRUCT*)get_result.GetBufPtr(), (DATA_STRUCT*)get_result.GetBufPtr() + get_result.GetLength()/sizeof(DATA_STRUCT)); } return result_vec.size();}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -