Giter Site home page Giter Site logo

sqlpp11's Introduction

sqlpp11

A type safe embedded domain specific language for SQL queries and results in C++.

!If you are a tenured user of sqlpp11, please note that
!  - with 0.61 the connector libraries for mysql/sqlite/postgresql got merged into the main repo.
!  - master has been renamed to main and is now the default branch

Documentation is found in docs.

So what is this about?

SQL and C++ are both strongly typed languages. Still, most C/C++ interfaces to SQL are based on constructing queries as strings and on interpreting arrays or maps of strings as results.

sqlpp11 is a templated library representing an embedded domain specific language (EDSL) that allows you to

  • define types representing tables and columns,
  • construct type safe queries checked at compile time for syntax errors, type errors, name errors and even some semantic errors,
  • interpret results by iterating over query-specific structs with appropriately named and typed members.

This results in several benefits, e.g.

  • the library user operates comfortably on structs and functions,
  • the compiler reports many kinds of errors long before the code enters unit testing or production,
  • the library hides the gory details of string construction for queries and interpreting results returned by select calls.

The library supports both static and dynamic queries. The former offers greater benefit in terms of type and consistency checking. The latter makes it easier to construct queries in flight.

sqlpp11’s core is vendor-neutral. Specific traits of databases (e.g. unsupported or non-standard features) are handled by connector libraries. Connector libraries can inform the developer of missing features at compile time. They also interpret expressions specifically where needed. For example, the connector could use the operator|| or the concat method for string concatenation without the developer being required to change the statement.

Connectors for MariaDB, MySQL, PostgreSQL, sqlite3, sqlcipher are included in this repository.

The library is already used in production but it is certainly not complete yet. Feature requests, bug reports, contributions to code or documentation are most welcome.

Examples:

For the examples, lets assume you have a table class representing something like

CREATE TABLE foo (
    id bigint,
    name varchar(50),
    hasFun bool
);

And we assume to have a database connection object:

TabFoo foo;
Db db(/* some arguments*/);

// selecting zero or more results, iterating over the results
for (const auto& row : db(select(foo.name, foo.hasFun).from(foo).where(foo.id > 17 and foo.name.like("%bar%"))))
{
    if (row.name.is_null())
        std::cerr << "name is null, will convert to empty string" << std::endl;
    std::string name = row.name;   // string-like fields are implicitly convertible to string
    bool hasFun = row.hasFun;          // bool fields are implicitly convertible to bool
}

// selecting ALL columns of a table
for (const auto& row : db(select(all_of(foo)).from(foo).where(foo.hasFun or foo.name == "joker")))
{
    int64_t id = row.id; // numeric fields are implicitly convertible to numeric c++ types
}

// selecting zero or one row, showing off with an alias:
SQLPP_ALIAS_PROVIDER(cheese);
if (const auto& row = db(select(foo.name.as(cheese)).from(foo).where(foo.id == 17)))
{
    std::cerr << "found: " << row.cheese << std::endl;
}

// selecting a single row with a single result:
return db(select(count(foo.id)).from(foo).unconditionally()).front().count;

Of course there are joins and subqueries, more functions, order_by, group_by etc.
These will be documented soon.

// A sample insert
db(insert_into(foo).set(foo.id = 17, foo.name = "bar", foo.hasFun = true));

// A sample update
db(update(foo).set(foo.hasFun = not foo.hasFun).where(foo.name != "nobody"));

// A sample delete
db(remove_from(foo).where(not foo.hasFun));

License:

sqlpp11 is distributed under the BSD 2-Clause License.

Status:

Branch / Compiler clang, gcc MSVC Test Coverage
master Build Status Build status Coverage Status
develop Build Status Build status Coverage Status

Additional information available:

Past talks about sqlpp11 and some coding concepts used within the library:

Requirements:

Compiler: sqlpp11 makes heavy use of C++11 and requires a recent compiler and STL. The following compilers are known to compile the test programs:

  • clang-3.4+ on Ubuntu-12.4
  • g++-4.8+ on Ubuntu-12.4
  • g++-4.8+ on cygwin 64bit
  • g++-4.9+ on Debian Unstable
  • Xcode-7 on OS X
  • MSVC 2015 Update 1 on Windows Server 2012

Database Connector: sqlpp11 requires a certain api in order to connect with the database, see database/api.h.

This repository includes the following connectors:

  • MySQL
  • MariaDB
  • SQLite3
  • SQLCipher
  • PostgreSQL

Other connectors can be found here:

Date Library: sqlpp11 requires Howard Hinnant’s date library for date and date_time data types. By default, sqlpp11 uses FetchContent to pull the library automatically in the project. If you want to use an already installed version of the library with find_package, set USE_SYSTEM_DATE option to ON.

Build and Install

Note: Depending on how you use the lib, you might not need to install it (see Basic Usage)

Build from Source:

Download and unpack the latest release from https://github.com/rbock/sqlpp11/releases or clone the repository. Inside the directory run the following commands:

cmake -B build
cmake --build build --target install

The last step will build the library and install it system wide, therefore it might need admins rights.

By default only the core library will be installed. To also install connectors set the appropriate variable to ON:

  • BUILD_MYSQL_CONNECTOR
  • BUILD_MARIADB_CONNECTOR
  • BUILD_POSTGRESQL_CONNECTOR
  • BUILD_SQLITE3_CONNECTOR
  • BUILD_SQLCIPHER_CONNECTOR

The library will check if all required dependencies are installed on the system. If connectors should be installed even if the dependencies are not yet available on the system, set DEPENDENCY_CHECK to OFF.

Example: Install the core library, sqlite3 connector and postgresql connector. Don’t check if the dependencies such as Sqlite3 are installed and don’t build any tests:

cmake -B build -DBUILD_POSTGRESQL_CONNECTOR=ON -DBUILD_SQLITE3_CONNECTOR=ON -DDEPENDENCY_CHECK=OFF -DBUILD_TESTING=OFF
cmake --build build --target install

Install via Homebrew (MacOS):

brew install marvin182/zapfhahn/sqlpp11

Some connectors can be installed with the formula. See brew info marvin182/zapfhahn/sqlpp11 for available options.

Build via vcpkg:

You can download and install sqlpp11 using the vcpkg dependency manager:

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
vcpkg install sqlpp11

The sqlpp11 port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.

The following connector libraries for sqlpp11 are maintained as a separate package in vcpkg:

Basic usage:

Use with cmake: The library officially supports two ways how it can be used with cmake. You can find examples for both methods in the examples folder.

  1. FetchContent (Recommended, no installation required)
  2. FindPackage (installation required, see above)

Both methods will provide the sqlpp11::sqlpp11 target as well as targets for each connector:

  • sqlpp11::mysql
  • sqlpp11::mariadb
  • sqlpp11::sqlite3
  • sqlpp11::sqlcipher
  • sqlpp11::postgresql

These targets will make sure all required dependencies are available and correctly linked and include directories are set correctly.

Create DDL files:

mysql: 'show create table MyDatabase.MyTable' #or
mysqldump --no-data MyDatabase > MyDatabase.sql

Create headers for them with provided Python script:

%sqlpp11_dir%/scripts/ddl2cpp ~/temp/MyTable.ddl  ~/temp/MyTable %DatabaseNamespaceForExample%

In case you’re getting notes about unsupported column type consider:

  • Take a look at the other datatypes in sqlpp11/data_types. They are not hard to implement.
  • Use the --datatype-file command line argument as described below.

Include generated header (MyTable.h), that’s all.

If you prefer Ruby over Python, you might want to take a look at https://github.com/douyw/sqlpp11gen

Unsupported column types:

Map unsupported column types to supported column types with a csv file:

One can use the --datatype-file command line argument for the ddl2cpp script to map unsupported column types to supported column types.

The format of the csv file is:

<dataType>, <col_type1>, <col_type2>
<dataType>, <col_type3>

Where <dataType> is one or more of the following internal types:

  • Boolean
  • Integer
  • Serial
  • FloatingPoint
  • Text
  • Blob
  • Date
  • DateTime
  • Time

Example:

Boolean, one_or_zero
Text, url, uuid

Contact:

sqlpp11's People

Contributors

andidog avatar blastrock avatar bloerwald avatar carlitxxx86 avatar cjcombrink avatar dermojo avatar dirkvdb avatar egorpugin avatar enwi avatar erroneous1 avatar faizol avatar ianda avatar isliser avatar leon0402 avatar lhkipp avatar linrongbin16 avatar macdue avatar marvin182 avatar meansquarederror avatar mikeneilson avatar mloskot avatar nixman avatar purplekarrot avatar rbock avatar rettichschnidi avatar sjoubert avatar snikulov avatar theodelrieu avatar tyroxx avatar volka 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  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  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  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  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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sqlpp11's Issues

error: static assertion failed: tvin may only be used with operators =, == and !=

Hi, sqlpp11 is really neat, I encounter compiler error with the following test case with 0.31,
while as I think this will compile and run with 0.29. Thanks, Mark

tvin.cpp:

#include <sqlpp11/sqlpp11.h>
#include <sqlpp11/sqlite3/sqlite3.h>
#include "tab.h"

using sqlpp_connection = sqlpp::sqlite3::connection;
using sqlpp_connection_config = sqlpp::sqlite3::connection_config;

int main(int argc, char *argv[])
{
    sqlpp_connection_config config;
    config.path_to_database = ":memory:";
    config.flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
    config.debug = true;
    sqlpp_connection db(config);
  db.execute(R"(CREATE TABLE tab (
    id integer not null,
    str character varying(10)
    ))");
  T::Tab t;
  db(remove_from(t).where(true));
  std::string s;
  db(sqlpp::insert_into(t).set(t.id = 1, t.str = sqlpp::tvin(s)));
  return 0;
}

tab.sql:

CREATE TABLE tab (
  id integer not null,
  str varchar
);

Makefile:

tvin:   tvin.cpp tab.h
    g++ -std=gnu++14 tvin.cpp

tab.h:  tab.sql
    ddl2cpp tab.sql tab T

Compiler error with g++-4.9.2:

-*- mode: compilation; default-directory: "/data/eng/dev/cxx/sqlpp/tvin/" -*-
Compilation started at Fri Mar 13 21:33:55

make
g++ -std=gnu++14 tvin.cpp
In file included from /usr/include/sqlpp11/boolean.h:35:0,
                 from /usr/include/sqlpp11/column_types.h:30,
                 from /usr/include/sqlpp11/sqlpp11.h:31,
                 from tvin.cpp:1:
/usr/include/sqlpp11/tvin.h: In instantiation of 'static void sqlpp::assert_tvin_with_correct_operator_t::_() [with T = void]':
/usr/include/sqlpp11/sqlite3/connection.h:282:60:   required from 'decltype (t._run((*(sqlpp::sqlite3::connection*)this))) sqlpp::sqlite3::connection::operator()(const T&) [with T = sqlpp::statement_t<void, sqlpp::insert_t, sqlpp::into_t<void, T::Tab>, sqlpp::insert_list_t<void, sqlpp::assignment_t<sqlpp::column_t<T::Tab, T::Tab_::Id>, sqlpp::integral_operand>, sqlpp::assignment_t<sqlpp::column_t<T::Tab, T::Tab_::Str>, sqlpp::tvin_arg_t<sqlpp::text_operand> > > >; decltype (t._run((*(sqlpp::sqlite3::connection*)this))) = long unsigned int]'
tvin.cpp:22:65:   required from here
/usr/include/sqlpp11/tvin.h:66:4: error: static assertion failed: tvin may only be used with operators =, == and !=
    static_assert(wrong_t<T>::value, "tvin may only be used with operators =, == and !=");
    ^
Makefile:2: recipe for target 'tvin' failed
make: *** [tvin] Error 1

Compilation exited abnormally with code 2 at Fri Mar 13 21:33:56

Is there any way to create tables?

Hi,

Tell me please, is there any way to create tables?
I.e. I was expected something like this:

if ( !db.exists<Table>() )
   db.create<Table>();

Parameter binding for connection::execute

Although the intention of sqlpp11 is to encourage expression tree usage over raw strings, there are still times when it is useful to pass a simple string SQL statement where no table static table definition can be relied on (for pragmas, working with master, etc.). Rather than rely on string quoting regimes and lexical casts, it would be helpful to have bound arguments to connection::execute(). For example:

bool writableSchema = /*...*/;
db->execute("PRAGMA writeable_schema = ?", writableSchema);

Jan Nikolas has implemented a nice variadic implementation which accomplishes this type of functionality utilizing variadics: http://boost-talk.blogspot.com/2012/04/sqlite-oop-v2-c11.html. It seems like it wouldn't be too hard to add on to sqlpp11.

conversion script 'ddl2cpp' does not support negative integer values

When SQL include a negative integer value, ddl2cpp failed to convert the SQL.

CREATE TABLE TEST (
  id varchar(255) PRIMARY KEY,
  num integer DEFAULT -1
) ENGINE=InnoDB DEFAULT CHARSET=utf8

I think we need to add something like this to support negative numbers

negativeSign = Literal('-')
ddlNum     = Combine(Optional(negativeSign) + Word(nums + "."))

Dynamic statements.

Hi,

I'm trying to use the dynamic select statements like dynamic_where and dynamic_limit like that:

auto s = dynamic_select(m_db, all_of(entry)).from(entry).dynamic_where();
s.add_where(true);

but I got the following compilation error:

error: ‘struct sqlpp::statement_t<sqlpp::sqlite3::connection, sqlpp::no_with_t, sqlpp::select_t, sqlpp::no_select_flag_list_t, sqlpp::select_column_list_t<...>, sqlpp::from_t<void, sdn_sql::Entry>, sqlpp::no_extra_tables_t, sqlpp::where_t<sqlpp::sqlite3::connection>, sqlpp::no_group_by_t, sqlpp::no_having_t, sqlpp::no_order_by_t, sqlpp::no_limit_t, sqlpp::no_offset_t, sqlpp::no_union_t>’ 
has no member named ‘add_where’

My code seems similar to the one on the wiki. I search the code and it does not seem to have the add_where method. Did you change the usage of dynamic select statements?

Best regards,
Simon

gcc 4.8.1 <invalid declaration of member template in local class>

FunctionTest.cpp compile error with gcc(4.8.1), error stack:

In file included from
sqlpp11/include/sqlpp11/table_base.h:31:0,
from sqlpp11/tests/TabSample.h:30,
from sqlpp11/tests/FunctionTest.cpp:26:
sqlpp11/tests/FunctionTest.cpp: In function ‘int main()’:
sqlpp11/include/sqlpp11/alias.h:41:5: error: invalid declaration of member template in local class
template
^
sqlpp11/tests/FunctionTest.cpp:377:3: note: in expansion of macro ‘SQLPP_ALIAS_PROVIDER_GENERATOR’
SQLPP_ALIAS_PROVIDER_GENERATOR(kaesekuchen);
^

Linker errors

Hello Roland,

At the moment I get errors like these when linking the program:

main.o:/home/matthijs/sometest/../sqlpp11/include/sqlpp11/verbatim_table.h:86: first defined here
rss/rss.os: In function `insert':
/home/matthijs/sometest/../sqlpp11/include/sqlpp11/insert.h:99: multiple definition of `sqlpp::insert()'
main.o:/home/matthijs/sometest/../sqlpp11/include/sqlpp11/insert.h:99: first defined here
rss/rss.os: In function `remove':
/home/matthijs/sometest/../sqlpp11/include/sqlpp11/remove.h:103: multiple definition of `sqlpp::remove()'
main.o:/home/matthijs/sometest/../sqlpp11/include/sqlpp11/remove.h:103: first defined here
rss/rss.os: In function `select':
/home/matthijs/sometest/../sqlpp11/include/sqlpp11/select.h:83: multiple definition of `sqlpp::select()'
main.o:/home/matthijs/sometest/../sqlpp11/include/sqlpp11/select.h:83: first defined here
clang: error: linker command failed with exit code 1 (use -v to see invocation)
scons: *** [main] Error 1

Probably these functions need to be inlined.

Regards, Matthijs

Upsert Support?

SQLite supports the "INSERT OR REPLACE" syntax for MERGE statements. It doesn't look like this is supported in sqlpp11. Are there plans to add this?

Which versions are usable?

Which version should I use as a consumer of the library:

  • master branch
  • develop branch
  • or the latest tag?

This important question also applies to the connector libraries.

MS Visual Studio 2015 support

Hi Roland

Does your project compile with the new Visual Studion 2015 version? Has anyone chequed this? I can't use your code unless I can also compile it on Windows with Visual Studio.
Peter

Build fails

Hello Roland,

I tried to build the tests but they fail with the following error:

-- The C compiler identification is GNU 4.9.1
-- The CXX compiler identification is GNU 4.9.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Using /usr/bin/c++ (compiler id: GNU)
-- Configuring done
CMake Error at tests/CMakeLists.txt:5 (add_executable):
  Cannot find source file:

    ResultTest.cpp

  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
  .hxx .in .txx
Call Stack (most recent call first):
  tests/CMakeLists.txt:18 (build_and_run)


-- Build files have been written to: /home/matthijs/sqlpp11/build

Regards, Matthijs

tvin support for prepared statements

When binding parameters for prepared statements: tvin cannot be used.
e.g:

preparedItemAdd.params.RefId = sqlpp::tvin(item.refId);

generates a compilation error

Question/Suggestion: Creation of CREATE TABLE statements

Hi,

First I just want to say I really like this library, I think you've done a great job here and hacking on the code helped me improve my understanding of Cpp11 a great deal. So thanks for that! :)

One of the things I've wrote is a little helper function that creates a CREATE TABLE statement from a given table. For example if we use the following PPGEN code
SQLPP_DECLARE_TABLE(
(tab_test),
(id , int , SQLPP_PRIMARY_KEY)
(name , varchar(255), SQLPP_NOT_NULL )
(feature, int , SQLPP_NOT_NULL )
)

My function outputs:
CREATE TABLE tab_test(id INTEGER AUTOINCREMENT NOT NULL,name TEXT NOT NULL,feature INTEGER NOT NULL);

Currently this only supports AUTOINCREMENT, NOT NULL and basic types (Everything is INTEGER or TEXT). But obviously this is just a quick&dirty proof of concept!

I was wondering if this is something you'd like to merge into the library. If so I'll work on making it more robust.

How to check if row exists?

Hi,

I need to check if user 'Bob' exists in the table:

CREATE TABLE users(
   id INT PRIMARY KEY,
   nickname varchar(32)
)

Usually I would have run the following query:

SELECT COUNT(*) FROM users WHERE nickname='Bob'

But I can not understand how to do this using sqlpp11?

Thanks!

Sybase Connector

I start implementing a sybase connector for sqlpp und I found some issues that is not easy to implement with sybase. I used this skeleton and I am currently a bit in trouble to implement this.

As far as I can see the statement will be executed and then the resultset is read row by row and for each row every single variable is filled with some bind option column by column. Is this true or am I missunderstanding something?

Sybase supports binding, but before the first row is read, you have to specify the variables for each column and bind it directly, meaing with each row you read the varibables are filles by Syase.

Is this kind of binding support, too?

Possible specifying database name?

Hi Roland,

Perhaps I missed it while browsing the code, but is there a way to specify the database in a query? I need to work with multiple databases (e.g., via ATTACH in SQLite), and I am unable to perform operations outside of the main (default) database. E.g., I perform the following:

ATTACH 'a.db' AS a;
ATTACH 'b.db' AS b;
SELECT t1.foo, t2.bar FROM a.my_table AS t1, b.my_table AS t2 WHERE t1.id = t2.id;

Currently, I'm unaware of a mechanism to provide such queries in a type-safe manner.

Defining custom user functions

Hi!
I was wandering if you ever think about writing a python parser for creating c++ code for custom user functions, similar to how you create c++ code for tables?
IMHO It should not be so hard... but I can be wrong :)

Cannot build the MySQL connector! Please some help

I downloaded the connector for mysql project and ran:

cmake CMakeLists.txt
make

and get this error:

Scanning dependencies of target sqlpp-mysql
[ 6%] Building CXX object src/CMakeFiles/sqlpp-mysql.dir/connection.cpp.o
In file included from /Users/juandent/Programs/C++/sqlpp11-connector-mysql-master/src/connection.cpp:30:
/Users/juandent/Programs/C++/sqlpp11-connector-mysql-master/src/detail/prepared_statement_handle.h:31:10: fatal error: 'mysql/mysql.h' file not
found

Using case in select statement.

Is it possible to perform requests with case statements using sqlpp11?

SELECT CASE WHEN col < 100 
            THEN col 
            ELSE othercol 
       END AS colname 
FROM table

Unable to insert into a table which has a field SQLPP_PRIMARY_KEY

SQLPP_DECLARE_TABLE(
    (clients)
    ,
    (login,     int,            SQLPP_PRIMARY_KEY)
    (name,      text,           SQLPP_NOT_NULL)
    (address,   text,           SQLPP_NOT_NULL)
)

const auto clients = clients::clients{};
auto i = insert_into(clients).columns(clients.login, clients.name);

Output:

insert_value_list.h(550): error C2338: at least one column argument has a must_not_insert tag in its definition

In sqlpp11\include\sqlpp11\ppgen\colops\primary_key.h I see such code

#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_SQLPP_PRIMARY_KEY(...) \
  ::sqlpp::tag::must_not_insert, ::sqlpp::tag::must_not_update

which prevent from inserting

Documentation for the in operator is missing.

I would like to perform the following request SELECT * FROM entry WHERE id IN (SELECT id FROM entry WHERE ...); but could not find any documentation on how to use the in operator.

Supported dumps

Hello,

What kind of dumps are supported by the ddl2cpp script? I was trying a PostgreSQL dump but that did not work out...

Regards, Matthijs

Sql++11 makes OS X's clang (Xcode-6.1.1) crash badly

Hi.

The stock clang version from the latest Xcode version (6.1.1) on OS X Yosemite crashes with a segmentation fault where building the library's tests (specifically, when building ResultTest.cpp.

While this is clearly a bug in the compiler, not in the library, this means the tests cannot currently be run on OS X and this is a problem for the library in the first place. It would be nice to get a reduced test case out of that bug so I can send a bug report to clang's folks.

I'm also going to test if the problem happens with clang trunk development branch and I will update the issue here.

Add support to compile with VS2013?

Hi Roland,

I appreciate your work on Sqlpp11 library, quite impressed with the concept and would like to use it in my project but unfortunately your code does not compile with VS2013. Can you please add support to get this compile with VS2013?

I know you mentioned somewhere you have used C++11 features that were not supported by VS 2013 compiler but there are alternatives you can use bu substituting with equivalent boost library implementation.

Can you please add support to get this compile using MSVC 2013?

Thanks
Praveen

access to connector / native db

Is there any some kind of fallback interface to send raw query through connector to database?
It could be quite useful when some features are not implemented and you agree to loose some speed doing string conversions.
For example, I suppose views are not supported and implementing them within sqlpp is a long work, but I could still query them using plain "SELECT blah-blah"

sqlp11 status

Roland,
what's the status of sqlpp11? I remember one year some discussion in boost mailing list but then I didn't see more info.
Is the lib still under development?
Any plan to submit to boost to be reviewed?

Thanks in advance

Storing prepared statements

What is the recommended way to store a prepared statement?

I have achieved to store a prepared select like this:

// structure for storing prepared statements
struct PreparedStatements
{
    std::unique_ptr<decltype(m_db->prepare(select(count(objects.Id).as(numObjects)).from(objects).where(objects.ParentId == parameter(objects.ParentId))))> childCount;
};

void Database::prepareStatements()
{
    auto childCount = m_db->prepare(
        select(count(objects.Id).as(numObjects))
        .from(objects)
        .where(objects.ParentId == parameter(objects.ParentId))
    );

    m_statements->childCount.reset(new decltype(childCount)(std::move(childCount)));
}

But this is not very intuitive and it forces me to duplicate the query to obtain the type of the prepared statement.
The deleted default constructor of prepared_statement_t also forces the use of a pointer to store the select.

Can this be done in a simpler way?

Windows (msvc++) support?

Hi,

Do you have any plans to add Windows support using the Microsoft compiler?
The latest preview of Visual Studio 2015 looks very promising (it compiles all my C++14 code).

(I use Linux as my primary platform, but some projects has to be x-platform, and under Windows, I tend to use the Microsoft compiler).

table_base.h or table.h ?

Hello Roland,

An easy to fix bug:

The ddl2cpp emits for each table an include:

#include <sqlpp11/table_base.h>

However that file does not exist, it should probably be table.h:

#include <sqlpp11/table.h>

Regards, Matthijs

autoincrement working with sqlite3?

Hello there and thank you for a really neat library! I would like to use autoincrement primary keys but am seeing some unexpected behavior.

CREATE TABLE user (
id int AUTO_INCREMENT PRIMARY KEY,
phone varchar(255) DEFAULT NULL
)

If I insert into this table with: db(insert_into(table).default_values() and then do a select of all rows, I see my id field with _is_null set to true and a value of 0, no matter how many times I insert. select statements that query by id do not return any results. The return value from my insert calls are auto-incrementing, so it seems like the data's getting down to the sqlite3 layer. Any idea what might be going on?

Thanks again.

Banning unconditional joins (aka cartesian or cross joins)

Hi,

So we just brought down a server by running something like

db(select(all_of(tabA)).from(tabA, tabB).where(true));

tabA and tabB are quite big, their unconditional join is ginormous. Too big for the server as it turned out.

One of the main purposes of sqlpp11 is to protect developers from those small mistakes that can kill your business if they are not caught. That's why for instance you cannot omit the where condition. You have to say where(true) to show your intent.

I therefore intend to disallow implicit joins like from(tabA, tabB) in future releases. This would enforce explicit joins

db(select(all_of(tabA)).from(tabA.join(tabB).on(someCondition)).where(true));

It would also enforce the join condition, making it much less likely that somebody forgets to add that condition to the where expression.

I guess I should deprecate the old functionality before removing it (although I am not exactly sure how to do this as [[deprecated]] is a C++14 feature)

Other thoughts?

Thanks in advance,

Roland

conversion script 'ddl2cpp' does not support boolean type

When I try to convert the following SQL to C++ header,

CREATE TABLE TEST (
  id varchar(255) PRIMARY KEY,
  flag boolean
) ENGINE=InnoDB DEFAULT CHARSET=utf8

, I got

Traceback (most recent call last):
  File "/home/mtakeda/src/cpp/test_sqlpp11/sqlpp11/scripts/ddl2cpp", line 159, in <module>
    traitslist = [NAMESPACE + '::' + types[sqlColumnType]];
KeyError: 'boolean'

The 'types' table in ddl2cpp has the key 'bool' instead of 'boolean'. Is this just a typo? I'm using the revision 'e152e29'.

Expression tree serializer should simplify parentheses

Certain queries are not possible to express with sqlpp11 due to excessive parentheses that are generated during serialization. For example, the query select(x).from(A).where(x.not_in(select(y).from(B))) will create an extra set of parentheses around the SELECT statement in the IN clause. This breaks on sqlite3. As an example (run with sqlite3 -echo < test.sql):

DROP TABLE IF EXISTS A;
CREATE TABLE A (x INTEGER);
DROP TABLE IF EXISTS B;
CREATE TABLE B (y INTEGER);

INSERT INTO A (x) VALUES (1), (2), (3);
INSERT INTO B (y) VALUES (1), (2), (3);

-- OK: correctly returns no results
SELECT x FROM A WHERE x NOT IN (SELECT y FROM B);

-- ERROR: returns '2' and '3' - this is the format that sqlpp11 generates
SELECT x FROM A WHERE x NOT IN ((SELECT y FROM B));

Functions are not aliased correctly in select-list

const auto a = select(count(tab.id)).from(tab).where(true).group_by(tab.name).as(sqlpp::alias::a);
for (const auto& row : db(select(a.count).from(a).where(a.count > 1)))
{
   // compiles fine, but produces an error in the DB, because the subselect is
   // SELECT COUNT(tab.id) FROM tab;
   // It should be COUNT(tab.id) AS "_COUNT" from tab;
   // Or something similar...
}

That is annoying, because I cannot just always serialize it as AS _COUNT, since it might be used in an expression like COUNT(id) % 2, for instance.

Async results support?

I recently came accross this library and it looks great however my use-case almost always needs async behavior. Since I'm not familiar with the code, the question might be a stupid one so please bear with me.

Would it be easy or difficult to extend the api to have async callbacks (lambdas) on completion of requests? Is anything like that planned?

sqlpp11-connector-odbc v0.01

I made an ODBC connector for sqlpp11. From what I can tell, using an ODBC connector for MySQL will allow you to connect to a MySQL database without becoming GPL because ODBC uses replaceable binaries (.so/.dll files) for the connectors and MySQL's components can easily be replaced by any other ODBC compliant database. While ODBC is available on Windows I don't think sqlpp11 is capable of wide characters, so ASCII encoded SQL would be a requirement. For thread safety, I would not share a connection object between threads, but you could pass the connection_config object to make a new connection in each thread.

Let me know if there are any issues I should correct.

Supported types

Hi,

In PostgreSQL there are many types, however in sqlpp11 I only see the types: boolean, integral, floating_point and text.

Take a look at: http://www.postgresql.org/docs/9.3/static/datatype.html

In other words, lots of types.

Is there a possibility to extend the library in such a way that it can support any type? For example, I would like to put a time / date field in an appropriate type (for example boost::posix_time::ptime)

Regards, Matthijs

clang-format used at all?

There is a clang-format configuration file in the repository, but the formatting of the sources files does not match it at all.

Which one should be corrected? The sources or the configuration file?

Verbatim support for prepared statements

When binding parameters for prepared statements: verbatim cannot be used.
e.g:

preparedItemAdd.params.Metadata = sqlpp::verbatim<sqlpp::integer>("last_insert_rowid()");

generates a compilation error

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.