levelDB按时间范围检索
来源:互联网 发布:excel2003删除重复数据 编辑:程序博客网 时间:2024/05/19 07:27
int InsertLevelDB(const char* key, const char* content) { //const char* Content = "2011-03-18 10:15:10,1.16591,2.27857,3.37197,4.45305,3.37197,1.16591,2.27857,3.37197,4.45305,5.52507,5.52507,4.45305,4.45305,4.45305,4.45305"; leveldb::DB* db = NULL; leveldb::Options options; options.create_if_missing = true; options.write_buffer_size = 8 * 1024* 1024; leveldb::Status status = leveldb::DB::Open(options, "c:/tmp/testdb", &db); leveldb::WriteOptions wo; wo.sync = false; if (status.ok()) { // cout << "write key: " << key << endl; leveldb::Status s = db->Put(wo, key, content); } else { printf("Insert LevelDB error\r\n"); } delete db; return 0; }
void GetKey(int device_id, time_t time_stamp, char* key) { char id[20]; _itoa_s(device_id, id, 10); strcpy_s(key, 50, id); char *timeStamp = TimeToChar(time_stamp); //自己实现的函数 strcat_s(key, 50, timeStamp); }
根据时间起止点,检索数据,主要是time_t与struct tm的特性,通过时间的加减,形成key值,从而得到value值,存放到value集合中。
int QueryData(int device_id, time_t begin_time, time_t end_time, vector<string>& history_data) { leveldb::DB* db = NULL; leveldb::Options options; options.create_if_missing = true; options.write_buffer_size = 8 * 1024* 1024; leveldb::Status status = leveldb::DB::Open(options, "c:/tmp/testdb", &db); if (!status.ok()) { delete db; printf("Insert LevelDB error\r\n"); return -1; } time_t cur_time = begin_time ; struct tm *beginTime, *curTime; curTime = localtime(&begin_time); char key[100]; string content; while(cur_time <= end_time) //循环得到key,取出value { curTime->tm_sec += 1; cur_time = mktime(curTime); memset(key, 0, sizeof(key)); GetKey(device_id, cur_time, key); leveldb::ReadOptions ro; leveldb::Status s = db->Get(ro, key, &content); if (!content.empty()) { history_data.push_back(content.c_str()); } } delete db; return 0; }
- levelDB按时间范围检索
- 按时间检索超大日志
- django 按时间范围查询数据库
- SQLite3中按时间范围分类排名(top 10)
- 按时间检索中,开始时间为00:00:00,结束时间为23:59:59
- 另类高效模糊检索之按时间片划区段分区检索
- access按时间统计
- 按时间分组查询
- mysql 按时间查询
- 按时间分段汇总
- 按时间计算
- logcat按时间排序
- mysql 按时间查询
- mysql 按时间查询
- ls 按时间排序
- sql 按时间查询
- MySQL按时间分组
- mysql按时间统计
- C语言部分字符串处理代码示例
- C# 判断字符串是否int类型
- torque maui 资源
- ListView中几个特别的属性
- 60个开发者不容错过的免费资源库
- levelDB按时间范围检索
- Android DOM解析XML
- InputStream 和 OutputStream
- Visual Studio 的Build Event 使用
- VS2012 下载地址
- Hibernate映射解析——七种映射关系(转来备忘)
- android音频通信
- FileInputStream 和 FileOutputStream
- 处理 url类