Ticket #1002: test.cpp

File test.cpp, 2.6 KB (added by Georg Semmler, 9 years ago)
Line 
1#include <iostream>
2#ifdef EARLY_TEMPLATE
3#define __EXECUTABLE__
4#ifdef __GNUG__
5#include <raslib/template_inst.hh>
6#endif
7#endif
8#include <rasdaman.hh>
9#include <rasodmg/database.hh>
10#include <rasodmg/partinsert.hh>
11
12#include "../common/src/logging/easylogging++.hh"
13_INITIALIZE_EASYLOGGINGPP
14
15int main(int argc, char **argv){
16 easyloggingpp::Configurations defaultConf;
17 defaultConf.setToDefault();
18#ifndef VERBOSE
19 defaultConf.setAll(easyloggingpp::ConfigurationType::ToStandardOutput, "false");
20 defaultConf.setAll(easyloggingpp::ConfigurationType::Enabled, "false");
21#endif
22 easyloggingpp::Loggers::reconfigureAllLoggers(defaultConf);
23
24 std::cout << "Insert data: ";
25
26 r_Minterval domain = r_Minterval(3)
27 << r_Sinterval((r_Range) 0,(r_Range) 1)
28 << r_Sinterval((r_Range) 0, (r_Range) 1)
29 << r_Sinterval((r_Range) 0, (r_Range) 1);
30
31 r_GMarray * data = reinterpret_cast<r_GMarray*>(new r_Marray<r_Float>(domain));
32 data->set_array_size(2 * 2 * 2 * sizeof(r_Float));
33 float *grid = reinterpret_cast<float*>(data->get_array());
34 for(std::size_t i = 0;i < 8;i++ ){
35 grid[i] = i;
36 }
37 r_Database db;
38 db.set_servername("localhost", 7001);
39 db.set_useridentification("rasadmin", "rasadmin");
40 db.open("RASBASE");
41 r_Partial_Insert insert(db, "test", "FloatCube", "FloatSet3", domain, sizeof(float));
42 insert.update(data);
43 delete data;
44 std::cout << "OK" << std::endl;
45
46 std::cout << "Query data: ";
47 r_Transaction t;
48 r_OQL_Query q("select t from test as t");
49 t.begin(r_Transaction::read_only);
50 r_Set<r_Ref_Any > returned;
51 r_oql_execute(q, returned);
52 auto iter = returned.create_iterator();
53 iter.reset();
54 if(iter.not_done()){
55 if(returned.get_type_schema()->type_id() == r_Type::COLLECTIONTYPE) {
56 r_Ref<r_GMarray > grid = (*iter);
57 float *values = reinterpret_cast<float*>(grid->get_array());
58 bool ok = true;
59 for(std::size_t i = 0;i < grid->get_array_size() / sizeof(float);i++ ){
60 if(values[i] != i){
61 if(i == 0){
62 std::cout << std::endl;
63 }
64 std::cout << "\tvalue at position " << i << "did not match" << std::endl;
65 ok = false;
66 }
67 }
68 t.commit();
69 if(ok){
70 std::cout << "OK" << std::endl;
71 }
72 }else{
73 t.commit();
74 std::cout << "did not return a collection" << std::endl;
75 }
76 }else{
77 t.commit();
78 std::cout << "returned nothing" << std::endl;
79 }
80 /* std::cout << "drop collection: ";
81 t.begin();
82 r_OQL_Query d("drop collection test");
83 r_oql_execute(d);
84 t.commit();
85 std::cout << "OK" << std::endl;
86 db.close();*/
87
88
89 return 0;
90}