Code Monkey home page Code Monkey logo

Comments (3)

xkikeg avatar xkikeg commented on July 29, 2024

SQLiteのstatement自体の問題としては、当然としてSQL文を一回実行してからイテレータを回すわけだけど、回している途中で後戻りができないこと。どういうことかって言うと、普通の線形リストとかだと

std::list<int> l = {1, 2, 3, 4};
std::list<int>::iterator itr1 = l.begin(),
   itr2 = ++itr1;
assert(*itr1 == 2);
assert(*itr2 == 1);

のように過去のイテレータをとっておけば使える。一方、SQL文はそうはいかない。解決策としてはC++標準のiostreamなどに入っているInput Iteratorの実装や仕様を見てみるといい。多分あれも過去のイテレータを取ってきても仕方ないものだろうから。

from ares.

xkikeg avatar xkikeg commented on July 29, 2024

streamのiteratorは終端イテレータとそれ以外でしか一致判定は成り立たない。つまり過去のイテレータをとっておく意味はない。
Input Iteratorのよくあるインターフェースとしては

SQLiteStmt::iterator itr=stmt.exec(), end;
while(itr != end)
{
   std::cout << static_cast<int>(*(itr++)) << std::endl;
}

とかなんだろうか。

from ares.

xkikeg avatar xkikeg commented on July 29, 2024
SQLite db(...);
try
{
   SQLiteStmt::iterator itr1 = db.execute("SELECT x FROM ..."), end;
   while(itr1 != end) { sum += *itr1; ++itr1; }
   SQLiteStmt stmt = db.query("SELECT x FROM ...");
   SQLiteStmt::iterator itr2 = stmt.execute();
   while(itr2 != end) { sum += *itr2; ++itr2; }
}catch(SQLiteError & e) {
   ...
}

っていうAPIがsqlite3_wrapper::SQLiteに必要なんじゃないかな。
と思ったけど、SQLiteStmtは今コピー禁止なんだけど、そのAPIだとファクトリ内でmoveしないといけない。C++03版を考えると面倒だなぁ。

from ares.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.