int main() { sql::connection_config config; config.path_to_database = ":memory:"; config.flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE; config.debug = true; sql::connection db(config); db.execute(R"(CREATE TABLE tab_sample ( alpha INTEGER PRIMARY KEY AUTOINCREMENT, beta bool DEFAULT NULL, gamma varchar(255) DEFAULT NULL ))"); const auto tab = TabSample{}; db(insert_into(tab).default_values()); db(insert_into(tab).default_values()); db(insert_into(tab).default_values()); std::set<int64_t> results; for (const auto& row : db(select(all_of(tab)).from(tab).unconditionally())) { results.insert(row.alpha); }; const auto expected = std::set<int64_t>{1, 2, 3}; assert(results == expected); return 0; }
void qsort_thread(struct thread_args *args) { struct timeval begin,end; struct merge_node * other = NULL, * m = NULL; #ifdef TIME_SORT_SINGLE gettimeofday(&begin, NULL); #endif //print("pid %d, begin:%d, end:%d\n",args->tid, low, high); qwordsort(args->mege.word_list, args->begin, args->end); #ifdef IN_THREAD_MEGRE other = get_from(); if(other != NULL) { print("in thread merge\n"); m = merge(other->word_list,args->mege.word_list); other->word_list = m; insert_into(other); } else #endif insert_into(&(args->mege)); #ifdef TIME_SORT_SINGLE gettimeofday(&end, NULL); usetime(&end, &begin, SORT); #endif }
int Ppgen(int, char*[]) { MockDb db{}; const auto p = tab_person::tab_person{}; const auto f = tab_feature::tab_feature{}; db(insert_into(f).set(f.name = "loves c++", f.fatal = false)); db(insert_into(f).default_values()); auto i = insert_into(p).columns(p.name, p.feature, p.age, p.level); i.values.add(p.name = "Roland", p.feature = 1, p.age = static_cast<unsigned int>(32), p.level = 3.14); i.values.add(p.name = "Zaphod", p.feature = sqlpp::default_value, p.age = static_cast<unsigned int>(16), p.level = 3.14 * 2); db(i); auto pi = db.prepare(insert_into(p).set(p.name = parameter(f.name), p.feature = parameter(p.feature), p.age = parameter(p.age), p.level = parameter(p.level))); pi.params.name = "likes java"; pi.params.feature = 2; pi.params.age = 21; pi.params.level = 3.14; db(pi); return 0; }
void Parser::process_command(InputType type) { switch (type){ case CREATE_: create_table(); break; case INSERT_: insert_into(); break; case OPEN_: open(); break; case CLOSE_: close(); break; case WRITE_: write(); break; case SHOW_: show(); break; case EXIT_: exit(); break; case DELETE_: delete_from(); break; case UPDATE_: update_to(); break; default: break; } }
std::shared_ptr<job::Job> make_storage_job(const Point& dest, item::Item* item) { auto e = item->parent; auto pos = e->assert_get<Position>(); clearance c = { (Security::Mask)(Security::INFRARED | Security::RED), Department::FACILITIES }; auto ais = std::make_shared<ai::SequenceAI>(); ais->add_task(ai::make_do_at(pos->as_point().as_point(), 10, "Collecting Item")); ais->add_task(ai::make_callbackai([=](ai::AI* ai){ delete e->remove<Position>(); auto it = ai->parent->assert_get<item::Item>(); auto it2 = e->assert_get<item::Item>(); it2->insert_into(it); })); ais->add_task(ai::make_do_at(dest.as_point(), 10, "Storing Item")); ais->add_task(ai::make_callbackai([=](ai::AI*){ auto it2 = e->assert_get<item::Item>(); it2->remove_from(); e->emplace<Position>(dest); })); auto script = ai::make_lockai(e->assert_get<item::Item>(), ais); return std::make_shared<job::Job>("Store Food", c, script); }
int main() { test::TabBar t; static_assert(sqlpp::can_be_null_t<decltype(t.alpha)>::value, "t.alpha can be null"); static_assert(not sqlpp::null_is_trivial_value_t<decltype(t.alpha)>::value, "t.alpha does not say null_is_trivial"); // Using a non-enforcing db for (const auto& row : db(select(all_of(t)).from(t).where(true))) { static_assert(sqlpp::can_be_null_t<decltype(row.alpha)>::value, "row.alpha can be null"); static_assert(sqlpp::null_is_trivial_value_t<decltype(row.alpha)>::value, "row.alpha interprets null_is_trivial"); static_assert(std::is_member_function_pointer<decltype(&decltype(row.alpha)::is_null)>::value, "Yikes"); using T = sqlpp::wrap_operand_t<decltype(row.alpha)>; static_assert(sqlpp::can_be_null_t<T>::value, "row.alpha can be null"); static_assert(sqlpp::is_result_field_t<T>::value, "result_fields are not wrapped"); bool x = (t.alpha == row.alpha)._rhs._is_null(); bool y = (t.alpha == row.alpha)._rhs._is_default(); std::cerr << x << std::endl; std::cerr << y << std::endl; for (const auto& sub : db(select(all_of(t)).from(t).where(t.alpha == row.alpha))) { std::cerr << sub.alpha << std::endl; } db(insert_into(t).set(t.beta = row.beta, t.gamma = false)); } sqlpp::select((t.alpha + 1).as(t.alpha)).flags(sqlpp::all).from(t); for (const auto& row : db(select(all_of(t)).from(t).where(true))) { static_assert(sqlpp::can_be_null_t<decltype(row.alpha)>::value, "row.alpha can be null"); static_assert(sqlpp::null_is_trivial_value_t<decltype(row.alpha)>::value, "row.alpha interprets null_is_trivial"); } // Using a non-enforcing db for (const auto& row : edb(select(all_of(t)).from(t).where(true))) { static_assert(sqlpp::can_be_null_t<decltype(row.alpha)>::value, "row.alpha can be null"); static_assert(not sqlpp::null_is_trivial_value_t<decltype(row.alpha)>::value, "row.alpha interprets null_is_trivial"); } sqlpp::select((t.alpha + 1).as(t.alpha)).flags(sqlpp::all).from(t); for (const auto& row : edb(select(all_of(t)).from(t).where(true))) { static_assert(sqlpp::can_be_null_t<decltype(row.alpha)>::value, "row.alpha can be null"); static_assert(not sqlpp::null_is_trivial_value_t<decltype(row.alpha)>::value, "row.alpha interprets null_is_trivial"); } return 0; }
int CustomQuery(int, char*[]) { const auto foo = test::TabFoo{}; const auto bar = test::TabBar{}; auto db = MockDb{}; // Unconditionally compare(__LINE__, custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.omega), from(foo), sqlpp::unconditionally()), "SELECT DISTINCT tab_foo.omega FROM tab_foo "); // A full select statement made individual clauses compare(__LINE__, custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.omega), from(foo.join(bar).on(foo.omega == bar.alpha)), where(bar.alpha > 17), group_by(foo.omega), having(avg(bar.alpha) > 19), order_by(foo.omega.asc()), sqlpp::limit(10u), sqlpp::offset(100u)), "SELECT DISTINCT tab_foo.omega FROM tab_foo INNER JOIN tab_bar ON (tab_foo.omega=tab_bar.alpha) WHERE " "(tab_bar.alpha>17) GROUP BY tab_foo.omega HAVING (AVG(tab_bar.alpha)>19) ORDER BY tab_foo.omega ASC " "LIMIT 10 OFFSET 100"); // A full select statement made individual clauses compare( __LINE__, custom_query(sqlpp::select(), dynamic_select_flags(db, sqlpp::distinct), dynamic_select_columns(db, foo.omega), dynamic_from(db, foo.join(bar).on(foo.omega == bar.alpha)), dynamic_where(db, bar.alpha > 17), dynamic_group_by(db, foo.omega), dynamic_having(db, avg(bar.alpha) > 19), dynamic_order_by(db, foo.omega.asc(), foo.psi.order(sqlpp::sort_type::desc)), sqlpp::dynamic_limit(db), sqlpp::dynamic_offset(db)), "SELECT DISTINCT tab_foo.omega FROM tab_foo INNER JOIN tab_bar ON (tab_foo.omega=tab_bar.alpha) WHERE " "(tab_bar.alpha>17) GROUP BY tab_foo.omega HAVING (AVG(tab_bar.alpha)>19) ORDER BY tab_foo.omega " "ASC,tab_foo.psi DESC "); // A pragma query for sqlite compare(__LINE__, custom_query(sqlpp::verbatim("PRAGMA user_version")).with_result_type_of(select(sqlpp::value(1).as(pragma))), " PRAGMA user_version"); // An insert from select for postgresql const auto x = 17; compare(__LINE__, custom_query(insert_into(foo).columns(foo.omega), select(sqlpp::value(x).as(foo.omega)) .from(foo) .where(not exists(select(foo.omega).from(foo).where(foo.omega == x)))), "INSERT INTO tab_foo (omega) " "SELECT 17 AS omega FROM tab_foo " "WHERE (NOT EXISTS(SELECT tab_foo.omega FROM tab_foo WHERE (tab_foo.omega=17)))"); return 0; }
int main() { MockDb db; test::TabPerson p; test::TabFeature f; db(insert_into(f).set(f.name = "loves c++", f.fatal = false)); //db(insert_into(f).set(f.nahme = "loves c++", f.fatal = false)); //db(insert_into(f).set(f.name == "loves c++", f.fatal = false)); //db(insert_into(f).set(f.name = "loves c++", f.fatal = "false")); //db(insert_into(p).set(f.name = "loves c++", f.fatal = false)); //db(insert_into(f).set(f.name = "loves c++", p.feature = 7)); //db(insert_into(f).set(f.id = 42, f.name = "loves c++", f.fatal = false)); //db(insert_into(f).set(f.name = "loves c++")); db(insert_into(f).default_values()); auto i = insert_into(p).columns(p.name, p.feature); i.values.add(p.name = "Roland", p.feature = 1); i.values.add(p.name = "Zaphod", p.feature = sqlpp::default_value); db(i); auto pi = db.prepare(insert_into(p).set(p.name = parameter(f.name), p.feature = parameter(p.feature))); pi.params.name = "likes java"; pi.params.feature = true; db(pi); }
int main(void) { printf("Enter N, M, j, and i\n"); unsigned N, M, j, i; while (scanf("%u%u%u%u", &N, &M, &j, &i) == 4) { printf("N =\t\t"); print_binary(N); printf("\nM =\t\t"); print_binary(M); printf("\nResult =\t"); print_binary(insert_into(N, M, j, i)); printf("\n"); } return 0; }
int _exec_stmt(DB * db, stmt_t * stmt) { switch (stmt->type) { case STMT_CREAT_TABLE: return create_table(db, stmt->table, stmt->cols, stmt->ncol); case STMT_DROP_TABLE: return drop_table(db, stmt->table); case STMT_CREAT_INDEX: return create_index(db, stmt->table, stmt->attr, stmt->index); case STMT_DROP_INDEX: return drop_index(db, stmt->index); case STMT_INSERT: return insert_into(db, stmt->table, NULL, stmt->vals, stmt->nval); case STMT_DELETE: return delete_from(db, stmt->table, stmt->conds, stmt->ncond); case STMT_SELECT: return select_and_print(db, stmt->table, stmt->cols, stmt->ncol, stmt->conds, stmt->ncond); } xerrno = ERR_INVSTMT; return -1; }
void World::save() { sql::connection db(getDbConfig()); box_db::Box tbl; // clear the table db(remove_from(tbl).unconditionally()); // insert all boxes for (const auto& box : _boxes) { btTransform trans; box.pose->getWorldTransform(trans); auto& p = trans.getOrigin(); float yaw, pitch, roll; trans.getBasis().getEulerYPR(yaw, pitch, roll); auto& c = box.color; db(insert_into(tbl).set( // position tbl.x = p.x(), tbl.y = p.y(), tbl.z = p.z(), // orientation tbl.yaw = yaw, tbl.pitch = pitch, tbl.roll = roll, // color tbl.red = c.r, tbl.green = c.g, tbl.blue = c.b)); } }
int main(int argc, char* argv[]) { CassCluster* cluster = NULL; CassSession* session = cass_session_new(); CassFuture* close_future = NULL; char* hosts = "127.0.0.1"; if (argc > 1) { hosts = argv[1]; } cluster = create_cluster(hosts); if (connect_session(session, cluster) != CASS_OK) { cass_cluster_free(cluster); cass_session_free(session); return -1; } execute_query(session, "CREATE KEYSPACE examples WITH replication = { \ 'class': 'SimpleStrategy', 'replication_factor': '3' };"); execute_query(session, "CREATE TABLE examples.date_time (key text PRIMARY KEY, d date, t time)"); insert_into(session, "test"); select_from(session, "test"); close_future = cass_session_close(session); cass_future_wait(close_future); cass_future_free(close_future); cass_cluster_free(cluster); cass_session_free(session); return 0; }
int DateTest(int, char*[]) { try { auto config = std::make_shared<sql::connection_config>(); #ifdef WIN32 config->dbname = "test"; config->user = "******"; config->password = "******"; config->debug = true; #else // TODO: assume there is a DB with the "username" as a name and the current user has "peer" access rights config->dbname = getenv("USER"); config->user = config->dbname; config->debug = true; #endif sql::connection db(config); for (int i = 0; i <= 1; ++i) { if (i) std::cerr << "Testing date/time WITH timezone\n"; else std::cerr << "Testing date/time WITHOUT timezone\n"; prepare_table(db, i); const auto tab = TabDateTime{}; db(insert_into(tab).default_values()); for (const auto& row: db(select(all_of(tab)).from(tab).unconditionally())) { require_equal(__LINE__, row.colDayPoint.is_null(), true); require_equal(__LINE__, row.colDayPoint.value(), ::sqlpp::chrono::day_point{}); require_equal(__LINE__, row.colTimePoint.is_null(), true); require_equal(__LINE__, row.colTimePoint.value(), ::sqlpp::chrono::microsecond_point{}); } db(update(tab).set(tab.colDayPoint = today, tab.colTimePoint = now).unconditionally()); for (const auto& row: db(select(all_of(tab)).from(tab).unconditionally())) { require_equal(__LINE__, row.colDayPoint.value(), today); require_equal(__LINE__, row.colTimePoint.value(), now); } db(update(tab).set(tab.colDayPoint = yesterday, tab.colTimePoint = today).unconditionally()); for (const auto& row: db(select(all_of(tab)).from(tab).unconditionally())) { require_equal(__LINE__, row.colDayPoint.value(), yesterday); require_equal(__LINE__, row.colTimePoint.value(), today); } auto prepared_update = db.prepare( update(tab).set(tab.colDayPoint = parameter(tab.colDayPoint), tab.colTimePoint = parameter(tab.colTimePoint)) .unconditionally()); prepared_update.params.colDayPoint = today; prepared_update.params.colTimePoint = now; std::cout << "---- running prepared update ----" << std::endl; db(prepared_update); std::cout << "---- finished prepared update ----" << std::endl; for (const auto& row: db(select(all_of(tab)).from(tab).unconditionally())) { require_equal(__LINE__, row.colDayPoint.value(), today); require_equal(__LINE__, row.colTimePoint.value(), now); } } } catch (std::exception& e) { std::cerr << "Exception: " << e.what() << std::endl; return 1; } catch (...) { std::cerr << "Unknown exception" << std::endl; return 1; } return 0; }
IDataStorage::ReturnCode DataStorage::addSensor(const std::string& userSensorName, const std::string& systemSensorName, const std::string& sensorType, const std::string& FAid, const std::string& kindOfSensor, const std::string& startingState, OnSuccessCallbackType onSuccessCallback, OnErrorCallbackType onErrorCallback) { if (isConnected == false) { return ReturnCode::WRONG_CONFIG; } if (onSuccessCallback == nullptr || onErrorCallback == nullptr) { return ReturnCode::NULLPTR_CALLBACKS; } { int inc = 0; const auto tabMainTable = DataDB::MainTable(); for (const auto &row : db->operator()(sqlpp::select(tabMainTable.systemSensorName).from(tabMainTable). where(tabMainTable.userSensorName == userSensorName))) { ++inc; break; } if (inc > 0) { dsThreadPool->enqueue(onErrorCallback, "Such user sensor name is already used."); return ReturnCode::SUCH_US_NAME_IS_USED; } inc = 0; for (const auto &row : db->operator()(sqlpp::select(tabMainTable.sensorType).from(tabMainTable). where(tabMainTable.systemSensorName == systemSensorName))) { ++inc; break; } if (inc > 0) { dsThreadPool->enqueue(onErrorCallback, "Such system sensor name is already used."); return ReturnCode::SUCH_SS_NAME_IS_USED; } } if (sensorType != sensorTypeConstants.binaryType && sensorType != sensorTypeConstants.monitorType && sensorType != sensorTypeConstants.manyStatesType) { return ReturnCode::WRONG_SENSOR_TYPE; } try { auto tabMainTable = DataDB::MainTable(); db->operator()(insert_into(tabMainTable).set(tabMainTable.userSensorName = userSensorName, tabMainTable.systemSensorName = systemSensorName, tabMainTable.sensorType = sensorType)); if (sensorType == sensorTypeConstants.binaryType) { auto tabBinaryType = DataDB::BinaryType(); db->operator()(insert_into(tabBinaryType).set(tabBinaryType.systemSensorName = systemSensorName, tabBinaryType.type = kindOfSensor, tabBinaryType.FAId = FAid, tabBinaryType.state = startingState)); dsThreadPool->enqueue(onSuccessCallback, "Sensor added"); return ReturnCode::SUCCESS; } if (sensorType == sensorTypeConstants.monitorType) { auto tabMonitorType = DataDB::MonitorType(); db->operator()(insert_into(tabMonitorType).set(tabMonitorType.systemSensorName = systemSensorName, tabMonitorType.type = kindOfSensor, tabMonitorType.FAId = FAid, tabMonitorType.state = startingState)); dsThreadPool->enqueue(onSuccessCallback, "Sensor added"); return ReturnCode::SUCCESS; } if (sensorType == sensorTypeConstants.manyStatesType) { auto tabManyStatesType = DataDB::BinaryType(); db->operator()(insert_into(tabManyStatesType).set(tabManyStatesType.systemSensorName = systemSensorName, tabManyStatesType.type = kindOfSensor, tabManyStatesType.FAId = FAid, tabManyStatesType.state = startingState)); dsThreadPool->enqueue(onSuccessCallback, "Sensor added"); return ReturnCode::SUCCESS; } } catch (std::exception& e) { dsThreadPool->enqueue(onErrorCallback, e.what()); return ReturnCode::EXCEPTION_ERROR; } return ReturnCode::SUCCESS; }
void Model::forward_a_step() { int K = 0; for( auto itm = passing_map.rbegin(); itm != passing_map.rend(); itm ++) { auto ing = itm->second; for (auto il = ing->begin(); il != ing->end(); il++) { if ( ! (*il)->valid) continue; // Location *l = com->get_a_location((*il)->label); if ( K % 500 == 0) cout << " K = " << K << ", " << l->name << endl; K ++; for ( vector <EDGE>::const_iterator it = l->outgoing.begin(); it != l->outgoing.end(); it++) { if ( ! (*il)->valid) break; Location *tmp = com->get_a_location(it->dest); if( ci) { if ( (l->signature & (unsigned)pow(2,N-1)) == 0 && (tmp->signature & (unsigned)pow(2, N-1)) != 0) { if ( constrain_release1(l)) { continue; } if ( count(l->signature, N) != cpus) continue; if ( constrain_release2(*il)) { continue; } } else if ( (l->signature & (unsigned)pow(2,N-1)) != 0 && (tmp->signature & (unsigned)pow(2,N-1))==0 && !tmp->is_bad) continue; } if (bp) { // now, let's consider the busy period while tk is waiting if ( (l->signature & (unsigned)pow(2,N-1)) != 0 && count(tmp->signature,N) > count(l->signature,N) && count(l->signature,N)>cpus) { int ti = 0; for (int h = 1; h < N; h++) if ( (l->signature & (unsigned)pow(2,h-1)) == 0 && (tmp->signature & (unsigned)pow(2, h-1)) != 0) { ti = h; break; } //cout << "before judgement " << (*il)->label << "-" << tmp->name << endl; if ( forward_release(*il, ti)) { //cout << (*il)->label << "-" << tmp->name << endl; continue; } } } NNC_Polyhedron poly = (*il)->cvx; guard_cvx(*it, poly); if( poly.is_empty()) continue; update_cvx(*it, poly); invar_cvx(tmp, poly); if( poly.is_empty()) continue; poly.time_elapse_assign(tmp->time_elapse); invar_cvx(tmp, poly); if( poly.is_empty()) continue; if( type==FAST_REACH && tmp->is_bad) { pair_sc sc(it->dest,poly, known_param_list, tmp->signature); //sc.pre = passing[k].state; //next.push_back(sc); cout << "The target is reached. Fast saving ...\n"; //fast_save(); throw 0; } auto sc = make_shared<pair_sc>(it->dest, poly, known_param_list, tmp->signature); if ( (l->signature & (unsigned)pow(2,N-1)) == 0 && (tmp->signature & (unsigned)pow(2, N-1)) != 0) sc->tk_new = true; if (contained_in(passing_map, sc, op, true)) continue; if (contained_in(next_map, sc, true, false)) continue; if (contained_in(passed_map, sc, op, false)) continue; (*il)->add_a_child(sc); insert_into(next_map, sc); sc->prior = (*il); } } } }
/**************************************************** * Function: cbInit * Description: ***************************************************/ int main() { int bytes_recv; //struct recv_struct array[5]; int i=0; /*array[0].seq_no = 0; array[0].AERT.tv_usec = ADD_TIME(total_elapsed_time,30); printf("seq %d, time %u\n",array[0].seq_no ,array[0].AERT.tv_usec); array[0].AERT.tv_sec = total_elapsed_time.tv_sec; array[0].mode =0; array[1].seq_no = 2; array[1].AERT.tv_usec = ADD_TIME(total_elapsed_time,40); printf("seq %d, time %u\n",array[1].seq_no, array[1].AERT.tv_usec); array[1].AERT.tv_sec = total_elapsed_time.tv_sec; array[1].mode =0; array[2].seq_no = 3; array[2].AERT.tv_usec = ADD_TIME(total_elapsed_time,20); array[2].AERT.tv_sec = total_elapsed_time.tv_sec; array[2].mode =0; array[4].seq_no = 3; array[4].AERT.tv_usec = ADD_TIME(total_elapsed_time,40); array[4].AERT.tv_sec = total_elapsed_time.tv_sec; array[4].mode =1; array[3].seq_no = 2; array[3].AERT.tv_usec = ADD_TIME(total_elapsed_time,40); array[3].AERT.tv_sec = total_elapsed_time.tv_sec; array[3].mode =1;*/ /*START:Establish connection as a server with tcpd_m2 as a client on port 1052*/ TIMER_in_socket = socket(AF_INET, SOCK_DGRAM, 0); TIMER_addr.sin_family = AF_INET; // Address family to use TIMER_addr.sin_port = htons(TIMER_PORT_IN); // Port number to use TIMER_addr.sin_addr.s_addr = htonl(INADDR_ANY); // Listen on any IP address if(bind(TIMER_in_socket, (struct sockaddr *)&TIMER_addr, sizeof(TIMER_addr))!=0) { perror("Binding failure tcpd_m2\n"); return 1; } /*END:Establish connection as a server with tcpd_m2 as a client on port 1052*/ addr_len = sizeof(struct sockaddr_in); while(1) { //printf("Iteration %d\n",i); //from_tcpd = array[i]; /*START:Recv data from TCPD*/ struct in_addr addr; int ret; /* fd_set is a fixed sized buffer */ fd_set TIMER_in_set; /* FD_ZERO clears a set */ FD_ZERO(&TIMER_in_set); /* FD_SET - adds the given file descriptor to the set */ FD_SET(TIMER_in_socket,&TIMER_in_set); ret = select(TIMER_in_socket+1, &TIMER_in_set, NULL, NULL, NULL); if (FD_ISSET(TIMER_in_socket, &TIMER_in_set)) { bytes_recv = recvfrom(TIMER_in_socket,&from_tcpd, sizeof (from_tcpd), 0, (struct sockaddr *)&TCPDM2_addr, &addr_len); /*END:Recv data from TCPD*/ addr.s_addr = TCPDM2_addr.sin_addr.s_addr; printf("Received seq %u sec %u usec %u from %s %u mode %d\n" ,from_tcpd.seq_no,from_tcpd.AERT.tv_sec,from_tcpd.AERT.tv_usec, inet_ntoa(addr),ntohs(TCPDM2_addr.sin_port),from_tcpd.mode); switch (from_tcpd.mode) { case INSERT_MODE: insert_into(); break; case DELETE_MODE: delete_from(); break; } print_list(); printf("\n"); } } /*START:Recv data from TCPD*/ return 0; }
int Interpret(int, char* []) { MockDb db = {}; MockDb::_serializer_context_t printer = {}; const auto f = test::TabFoo{}; const auto t = test::TabBar{}; select(t.alpha.as(t.beta)); serialize(insert_into(t).columns(t.beta, t.gamma), printer).str(); { auto i = insert_into(t).columns(t.gamma, t.beta); i.values.add(t.gamma = true, t.beta = "cheesecake"); serialize(i, printer).str(); i.values.add(t.gamma = false, t.beta = sqlpp::tvin("coffee")); i.values.add(t.gamma = false, t.beta = sqlpp::tvin(std::string())); serialize(i, printer).str(); i.values.add(t.gamma = sqlpp::default_value, t.beta = sqlpp::null); serialize(i, printer).str(); } serialize(t.alpha = sqlpp::null, printer).str(); serialize(t.alpha = sqlpp::default_value, printer).str(); serialize(t.alpha, printer).str(); serialize(-t.alpha, printer).str(); serialize(+t.alpha, printer).str(); serialize(-(t.alpha + 7), printer).str(); serialize(t.alpha = 0, printer).str(); serialize(t.alpha = sqlpp::tvin(0), printer).str(); serialize(t.alpha == 0, printer).str(); serialize(t.alpha == sqlpp::tvin(0), printer).str(); serialize(t.alpha != 0, printer).str(); serialize(t.gamma != sqlpp::tvin(false), printer).str(); serialize(t.alpha == 7, printer).str(); serialize(t.delta = sqlpp::tvin(0), printer).str(); serialize(t.beta + "kaesekuchen", printer).str(); serialize(sqlpp::select(), printer).str(); serialize(sqlpp::select().flags(sqlpp::distinct), printer).str(); serialize(select(t.alpha, t.beta).flags(sqlpp::distinct), printer).str(); serialize(select(t.alpha, t.beta), printer).str(); serialize(select(t.alpha, t.beta).from(t), printer).str(); serialize(select(t.alpha, t.beta).from(t).where(t.alpha == 3), printer).str(); serialize(select(t.alpha, t.beta).from(t).where(t.alpha == 3).group_by(t.gamma), printer).str(); serialize(select(t.alpha, t.beta).from(t).where(t.alpha == 3).group_by(t.gamma).having(t.beta.like("%kuchen")), printer).str(); serialize(select(t.alpha, t.beta) .from(t) .where(t.alpha == 3) .group_by(t.gamma) .having(t.beta.like("%kuchen")) .order_by(t.beta.asc()), printer).str(); serialize(select(t.alpha, t.beta) .from(t) .where(t.alpha == 3) .group_by(t.gamma) .having(t.beta.like("%kuchen")) .order_by(t.beta.asc()) .limit(17) .offset(3), printer).str(); serialize(parameter(sqlpp::bigint(), t.alpha), printer).str(); serialize(parameter(t.alpha), printer).str(); serialize(t.alpha == parameter(t.alpha), printer).str(); serialize(t.alpha == parameter(t.alpha) and (t.beta + "gimmick").like(parameter(t.beta)), printer).str(); serialize(insert_into(t), printer).str(); serialize(insert_into(f).default_values(), printer).str(); serialize(insert_into(t).set(t.gamma = true), printer).str(); // serialize(insert_into(t).set(t.gamma = sqlpp::tvin(false)), printer).str(); cannot test this since gamma cannot be // null and a static assert is thrown serialize(update(t), printer).str(); serialize(update(t).set(t.gamma = true), printer).str(); serialize(update(t).set(t.gamma = true).where(t.beta.in("kaesekuchen", "cheesecake")), printer).str(); serialize(update(t).set(t.gamma = true).where(t.beta.in()), printer).str(); serialize(remove_from(t), printer).str(); serialize(remove_from(t).using_(t), printer).str(); serialize(remove_from(t).where(t.alpha == sqlpp::tvin(0)), printer).str(); serialize(remove_from(t).using_(t).where(t.alpha == sqlpp::tvin(0)), printer).str(); // functions serialize(sqlpp::value(7), printer).str(); serialize(sqlpp::verbatim<sqlpp::integral>("irgendwas integrales"), printer).str(); serialize(sqlpp::value_list(std::vector<int>({1, 2, 3, 4, 5, 6, 8})), printer).str(); serialize(exists(select(t.alpha).from(t)), printer).str(); serialize(any(select(t.alpha).from(t)), printer).str(); serialize(some(select(t.alpha).from(t)), printer).str(); serialize(count(t.alpha), printer).str(); serialize(min(t.alpha), printer).str(); serialize(max(t.alpha), printer).str(); serialize(avg(t.alpha), printer).str(); serialize(sum(t.alpha), printer).str(); serialize(sqlpp::verbatim_table("whatever"), printer).str(); // alias serialize(t.as(t.alpha), printer).str(); serialize(t.as(t.alpha).beta, printer).str(); // select alias serialize(select(t.alpha).from(t).where(t.beta > "kaesekuchen").as(t.gamma), printer).str(); serialize(t.alpha.is_null(), printer).str(); // join serialize(t.inner_join(t.as(t.alpha)).on(t.beta == t.as(t.alpha).beta), printer).str(); { auto inner = t.inner_join(t.as(t.alpha)).on(t.beta == t.as(t.alpha).beta); serialize(select(t.alpha).from(inner), printer).str(); } // multi_column serialize(multi_column(t.alpha, (t.beta + "cake").as(t.gamma)).as(t.alpha), printer).str(); serialize(multi_column(all_of(t)).as(t), printer).str(); serialize(all_of(t).as(t), printer).str(); // dynamic select { auto s = dynamic_select(db).dynamic_flags().dynamic_columns().from(t); s.selected_columns.add(t.beta); s.selected_columns.add(t.gamma); serialize(s, printer).str(); } { auto s = dynamic_select(db).dynamic_flags().dynamic_columns().from(t); s.select_flags.add(sqlpp::distinct); s.selected_columns.add(t.beta); s.selected_columns.add(t.gamma); serialize(s, printer).str(); } { // Behold, dynamically constructed queries might compile but be illegal SQL auto s = dynamic_select(db).dynamic_flags(sqlpp::distinct).dynamic_columns(t.alpha); s.select_flags.add(sqlpp::all); s.selected_columns.add(without_table_check(t.beta)); s.selected_columns.add(without_table_check(t.gamma)); serialize(s, printer).str(); } // distinct aggregate serialize(count(sqlpp::distinct, t.alpha % 7), printer).str(); serialize(avg(sqlpp::distinct, t.alpha - 7), printer).str(); serialize(sum(sqlpp::distinct, t.alpha + 7), printer).str(); serialize(select(all_of(t)).from(t).unconditionally(), printer).str(); for (const auto& row : db(select(all_of(t)).from(t).unconditionally())) { serialize(row.alpha, printer); serialize(row.beta, printer); serialize(row.gamma, printer); } get_sql_name(t); get_sql_name(t.alpha); flatten(t.alpha == 7, db); auto x = boolean_expression(db, t.alpha == 7); x = sqlpp::boolean_expression<MockDb>(t.beta.like("%cheesecake")); x = x and boolean_expression(db, t.gamma); std::cerr << "----------------------------" << std::endl; printer.reset(); std::cerr << serialize(x, printer).str() << std::endl; printer.reset(); std::cerr << serialize(select(all_of(t)).from(t).where(t.alpha.in(select(f.epsilon).from(f).unconditionally())), printer).str() << std::endl; printer.reset(); std::cerr << serialize(select(all_of(t)).from(t).where(t.alpha.in()), printer).str() << std::endl; printer.reset(); std::cerr << serialize(select(all_of(t)).from(t).where(t.alpha.not_in()), printer).str() << std::endl; auto schema = db.attach("lorem"); auto s = schema_qualified_table(schema, t).as(sqlpp::alias::x); printer.reset(); std::cerr << serialize(select(all_of(s)).from(s).unconditionally(), printer).str() << std::endl; printer.reset(); std::cerr << serialize(sqlpp::case_when(true).then(t.alpha).else_(t.alpha + 1).as(t.beta), printer).str() << std::endl; return 0; }
wchar_t* recognize(kanji unknown, kanjis data) { kanji dummy_k; dummy_k.c_strokes = 0; dummy_k.c_points = 0; dummy_k.xy = 0; dummy_k.kji = 'c'; result best_100[100]; result dummy; dummy.weight = 100000; dummy.k = dummy_k; for(int i=0;i<100;i++) { best_100[i] = dummy; } // coarse recognition with endpoints int (*p_endpoint) (kanji, int, kanji, int); p_endpoint = endpoint; int (*p_endpoint_conc) (kanji, int, kanji, int, int); p_endpoint_conc = endpoint_conc; wchar_t hirag_ri = L'\u308a'; for(int i=0;i<data.count;i++) { //if(data.arr[i].kji == unknown.kji || data.arr[i].kji == hirag_ri) { { // printf("unknown:\n"); // print_kanji(unknown); // printf("from data-set:\n"); // print_kanji(data.arr[i]); kanji larger; kanji smaller; if(unknown.c_strokes >= data.arr[i].c_strokes) { larger = unknown; smaller = data.arr[i]; } else { larger = data.arr[i]; smaller = unknown; } smap sm_init_ep = get_initial_map(larger, smaller, p_endpoint); // print_smap(sm_init_ep); smap sm_comp_ep = complete_map(sm_init_ep, larger, smaller, p_endpoint_conc); // print_smap(sm_comp_ep); int weight_i = compute_coarse_weight(sm_comp_ep, larger, smaller); // wprintf(L"\n coarse weight: %i for %lc ", weight_i, data.arr[i].kji); // weight_i = (10 * larger.c_strokes * weight_i)/(smaller.c_strokes); // return ((largeX.length*10)/(smallX.length))*weight; // wprintf(L"\n coarse weight: %i for %lc ", weight_i, data.arr[i].kji); if(1) { insert_into(best_100, 100, weight_i, data.arr[i]); // wprintf(L"\n %lc ", data.arr[i].kji); // print_smap(sm_comp_ep); // printf("weight: %i\n",weight_i); } free(sm_init_ep.m); // free(sm_comp_ep.m); } } // fine recognition with initialization by // init-dist and completion by whole-dist dummy.weight = 100000; dummy.k = dummy_k; result best_10[10]; for(int i=0;i<10;i++) { best_10[i] = dummy; } int (*p_initial) (kanji, int, kanji, int); p_initial = initial; int (*p_whole) (kanji, int, kanji, int, int); p_whole = whole; int (*p_whole_delta) (kanji, int, kanji, int, int); p_whole_delta = whole_delta; for (int i = 0; i < 100; i++) { // skip the inserted dummy kanji // which has zero strokes // skip "smaller" kanji if (best_100[i].k.c_strokes > 0) { // && best_100[i].k.kji == unknown.kji) { if(best_100[i].k.kji == unknown.kji ) { // printf("within best 100\n"); } kanji larger; kanji smaller; if (unknown.c_strokes >= best_100[i].k.c_strokes) { larger = unknown; smaller = best_100[i].k; } else { larger = best_100[i].k; smaller = unknown; } smap sm_init_wh = get_initial_map(larger, smaller, p_initial); smap sm_comp_wh; if (unknown.c_strokes < 5) { sm_comp_wh = complete_map(sm_init_wh, larger, smaller, p_whole_delta); } else { sm_comp_wh = complete_map(sm_init_wh, larger, smaller, p_whole); } // print_smap(sm_comp_wh); int weight_i = 0; if(unknown.c_strokes < 5) { wchar_t wc = strtol("30c8", NULL, 16); if(unknown.kji == wc) { // wprintf(L"%lc and %lc",larger.kji, smaller.kji); // print_smap(sm_comp_wh); } weight_i = compute_fine_weight(sm_comp_wh, larger, smaller, true); } else { weight_i = compute_fine_weight(sm_comp_wh, larger, smaller, false); } // weight_i = compute_initial_weight(sm_comp_wh, larger, smaller); // wprintf(L"\n fine weight: %i for %lc ", weight_i, best_100[i].k.kji); insert_into(best_10, 10, weight_i, best_100[i].k); free(sm_init_wh.m); //free(sm_comp_wh.m); } } static wchar_t matching_kjis[10]; for(int i=0;i<10;i++) { matching_kjis[i] = best_10[i].k.kji; // printf("w: %i", best_10[i].weight); } // printf("\n"); return matching_kjis; }
/*mulit-thread sorting words */ int sortwords_multi(struct word * wlist_head) { pthread_t id[THREAD_NUM]; int nums = wlist_head->len; struct thread_args * targs[THREAD_NUM]; struct thread_args * leftarg; void * res; int ret = -1; int i = 0; int period = nums/THREAD_NUM; int left = nums % THREAD_NUM; struct word * word_list = wlist_head->next; struct merge_node * one=NULL,*two=NULL, *m=NULL; struct timeval begin,end; #ifdef TIME_SORT gettimeofday(&begin, NULL); #endif for(i = 0; i < THREAD_NUM; i++) { targs[i] = calloc(1,sizeof(struct thread_args)); if(targs[i] == NULL) { printf("calloc fail\n"); } word_list[(i+1)*period - 1].next = NULL; targs[i]->begin = 0; targs[i]->end = period-1; targs[i]->tid = i+1; targs[i]->mege.word_list = &word_list[i*period]; ret = pthread_create(&id[i],NULL,qsort_thread,targs[i]); if(ret<0) { printf("pthread create error %d\n",i); } } if(left!=0) { //print("pid %d, left=%d, begin:%d, end:%d \n",0,left, i*period, nums-1); leftarg = calloc(1,sizeof(struct thread_args)); if(leftarg == NULL) { printf("calloc fail\n"); } leftarg->begin = 0; leftarg->end = nums - i*period - 1; leftarg->mege.word_list = &word_list[i*period]; qsort_thread(leftarg); } for(i = 0; i < THREAD_NUM; i++) { ret = pthread_join(id[i],NULL); } #ifdef TIME_SORT gettimeofday(&end, NULL); usetime(&end, &begin, SORT); #endif #ifdef TIME_MEGRE gettimeofday(&begin, NULL); #endif // merge while(1){ if(g_list == NULL) { break; } if(one == NULL) { one = get_from(); continue; } else { two = get_from(); } if( one != NULL && two != NULL) { m = merge(one->word_list,two->word_list); one->word_list = m; wlist_head->next = m; insert_into(one); one = two = NULL; } } #ifdef TIME_MEGRE gettimeofday(&end, NULL); usetime(&end, &begin, MEGRE); #endif }