Giter Site home page Giter Site logo

vsqlite--'s Introduction

Build Status Coverity Scan Build Status

VSQLite++ - A welldesigned and portable SQLite3 Wrapper for C++ (C) 2006-2014 by virtuosic bytes - [email protected]

Author: Vinzenz Feenstra

License: BSD-3

Join the chat at https://gitter.im/vinzenz/vsqlite--

Supported Compilers

  • g++ 4.x
  • MSVC 2005-2013
  • Clang 3.x

Operating Systems

  • Linux
  • Windows
  • Mac OS X

Dependencies

Additional notices:

  • Please let me know if you want to suggest features
  • Contributions are welcome
  • Proposals for Design Improvement are welcome

vsqlite--'s People

Contributors

bstarynk avatar edwardbetts avatar genisysram avatar gitter-badger avatar ixasuhan avatar michihenning avatar mmickey avatar phpdan avatar sryze avatar vinzenz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

vsqlite--'s Issues

a little type in sample code

Hi
First thing first, thank you so much for sharing your efforts

I think there is just a little typo in given sample code
line
sqlite::execute insert(con, "INSERT INTO TEST VALUE(?, ?);");
should be
sqlite::execute ins(con, "INSERT INTO TEST VALUES(?, ?);");

Incorrect row count for query

It looks like result::get_row_count() always returns zero after running a query. For example:

sqlite::query q(conn_, "SELECT key, size FROM cache ORDER BY access_time ASC;");
auto r = q.emit_result();
cerr << "row_count: " << r->get_row_count() << endl;

This prints 0 for a table with three records.

The problem I have is that I want to iterate over the results to do things with each record. But I can't. The approach in the example does not work:

do
{
cerr << "key: " << y->get_string(0) << endl;
} while (y->next_row());

The problem here is that the result set may be empty, in which case I don't want to do anything. But I cannot write a pre-tested loop without get_row_count(). The do loop will execute at least once, even if there are no results.

If I do run the above loop on an empty result set, I get

key: NULL

That's despite the fact that the corresponding table column is defined as NOT NULL.

What's the suggested way to process results row by row and doing nothing if there are no results?

Typos in the website example code

Hello, I very much like your library and would like to bring an issue to your attention.

There appears to be two typos in the example code on the project's website.
http://vsqlite.virtuosic-bytes.com/

The first is execption instead of exception. The other is VALUE instead of VALUES in the prepared SQL statement.

I hope this helps.

The function `emit` shadows Qt's emit functionality

The function emit works without Qt and Qt works without vsqlite++. When using both together, you get the following compiler error:

In file included from src/./vsqlite++/include/sqlite/execute.hpp:35,
                 from src/./database.hpp:5,
                 from src/./todo.hpp:8,
                 from src/gui/mainwindow.cpp:9:
src/vsqlite++/include/sqlite/command.hpp:80:19: error: expected unqualified-id before ‘)’ token
         bool emit();

A simple renaming of the function emit(), which just forwards step(), in vsqlite++ solves this error.

Is there any reason for sqlite::command::emit or will it stay equal to sqlite::command::step?

Coding style & unifying eol

Hi Vinzenz, I would propose to run a dos2unix on cpp & hpp files to unify the end of line style on the whole project.

Would you accept this changes ?

Transaction destructor performs a commit

transaction::~transaction(){
if (m_isActive) commit();
}

This seems really strange. Why does the destructor commit the transaction instead of rolling it back? The whole point of RAII is to make sure that, if something goes wrong, things are cleaned up. Consider something like this:

{
transaction t;
// Some SQL statements here
// Some other C++ code here that might throw
// Some more SQL statements here
} // t committed here, why?

If something throws in this block, the transaction will still be committed, even though there was an exception. This seems really counter-intuitive. I would expect the transaction to be rolled back unless it is explicitly committed, because that is the fail-safe behavior. I believe the destructor should roll back rather than commit. Can you explain why things are the other way around?

Constructor unconditionally creates the DB

The connection constructor creates a new DB if it doesn't exist yet, with no way to suppress this behavior. That's really unfortunate because one silly typo is enough to end up working with a new empty DB instead of an existing one.

There should be a way to connect to a DB only if it exists already and fail other wise.
An overload for the connection constructor that takes an enum as a second argument could be used to fix this. Something like

class connection {
// ...
enum OpenMode { Create, NoCreate };

connection(std::string cons t& db, OpenMode mode);

The existing constructor could then be changed to forward to the new one, supplying Create as the second argument.

Add unit and funtional tests

In order to to fully test the library there should be unit and functional tests ensuring the stability anf correctness of the library.

Clarify Licence equivalence

Dear Authors, we would like to package your software in our build farm build.opensuse.org giving the opportunity to thousand of users to be able to get the software directly with their package manager.

Unfortunately, we would like to have clarification about the license. All the allowed and well known licenses are located there.
https://docs.google.com/spreadsheet/pub?key=0AqPp4y2wyQsbdGQ1V3pRRDg5NEpGVWpubzdRZ0tjUWc
Could you have a look, and clarify the kind of BSD like you use.

Thanks

DB is create if it doesn't exist

When I construct the connection, if the database doesn't exist, it is created. That's really inconvenient sometimes because a silly typo can mean that I operate on a new empty database instead of the intended, already-existing one.

There should be a way to construct the connection such that it throws if the database doesn't exist.

destructor of transaction class throws an exception

The problem is that in at least current SQLite documentation is stated that:

COMMIT is an an alias to END TRANSACTION
and SQLite does not support nested transaction

now the code in destructor is:

transaction::~transaction() {
    commit(); // effectively sends COMMIT
    end(); // sends END TRANSACTION
}

It effectively tries to end transaction twice as it was a nested transaction. SQlite team also probably don't want to make possible an assumption that it is safe to execute END TRANSACTION twice because in future versions of SQLite when nested transactions would be supported it will break existing code.

With regards,

Janusz Korczak

C++11 compatibility?

What about C++11 (or C++14) compatibilty (using a recent compiler like GCC 4.9 or future 5.0, or Clang/LLVM 3.5 or 3.6, on Linux)?

In particular, I'm interested in

  • using std::shared_ptr, not boost::shared_ptr
  • using C++11 closures and/or for-ranged loops for iterating on the rows resulting from some SQL request.

Regards.

next_row() returns true beyond the end of results

I have a table containing a single row and run a select on it. The code looks something like this:

sqlite::query q(conn_, "SELECT access_time, size FROM mytable ORDER BY access_time ASC;");
auto r = q.get_result();

cerr << "first loop" << endl;
while (r->next_row())
{
     cerr << "next row is true" << endl;
}
cerr << "next row is false" << endl;

cerr << "second loop" << endl;
while (r->next_row())
{
     cerr << "next row is true" << endl;
}
cerr << "next row is false" << endl;

The output is:

first loop
next row is true
next row is false
second loop
next row is true
next row is false

I find this extremely surprising. It appears that, once next_row( ) has returned false, it returns true if I call it again, despite the fact that the iterator has already been advanced to the end of the result. I believe that next_row() should continue to return false once the iterator has reached the end of the results, no matter how often I call next_row().

No error code in database_exception

When I get a database_exception, I can get at the string for the error message, but not at the underlying error code. That's really inconvenient because I can't selectively react to different error conditions other than by parsing the error string. Doing that is really brittle. It would be nice to have an accessor on the exception classes that returns the underlying error code.

make install doesn't install headers

make install will install the library binary, but not the header files.
The usual for a library package is to install both the library and header files on make install, but the Makefile.am file is set to install only libs. Headers should be added to a _HEADERS section.

Cannot insert empty blob

It seems there is a problem in bind():

void command::bind(int idx, std::vector const & v)
{
bind(idx,&v.at(0),v.size());
}

If I call this with an empty vector, the bind throws because v.at(0) is out of range. I believe this should be something like:

if (!v.size() == 0) {
bind(idx,&v.at(0),v.size());
} else {
bind(++last_arg_idx);
}

Compiling in Windows msys2

I have compiled this project in msys2 and not compile because in msys2 the boost library is compiled in multithread mode (eg: libboost_system-mt.dll)

/bin/sh ./libtool --tag=CXX --mode=link g++ -I ./include -W -Wall -pedantic -W -std=c++0x -g -O2 -o vsqlitepp_example.exe examples/vsqlitepp_example-sqlite_wrapper.o libvsqlitepp.la
libtool: link: g++ -I ./include -W -Wall -pedantic -W -std=c++0x -g -O2 -o .libs/vsqlitepp_example.exe examples/vsqlitepp_example-sqlite_wrapper.o ./.libs/libvsqlitepp.a -lsqlite3 -lboost_system -lboost_filesystem
C:/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/5.3.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lboost_system
C:/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/5.3.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lboost_filesystem
collect2.exe: error: ld returned 1 exit status
Makefile:554: recipe for target 'vsqlitepp_example.exe' failed
make[1]: *** [vsqlitepp_example.exe] Error 1
make[1]: Leaving directory '/home/apons/vsqlite--'
Makefile:695: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1

Can you use boost macros for resolve this: https://github.com/tsuna/boost.m4

Workaround (Execute manual) :

g++ -I ./include -W -Wall -pedantic -W -std=c++0x -g -O2   -o vsqlitepp_example.exe examples/vsqlitepp_example-sqlite_wrapper.o libvsqlitepp.la
libtool: link: g++ -I ./include -W -Wall -pedantic -W -std=c++0x -g -O2 -o .libs/vsqlitepp_example.exe examples/vsqlitepp_example-sqlite_wrapper.o  ./.libs/libvsqlitepp.a -lsqlite3 -lboost_system-mt -lboost_filesystem-mt

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.