Code Monkey home page Code Monkey logo

sqlite's Introduction

SQLite

Simple SQLite C++ classes

Example

#include "SQlite.hpp"
SQLite database;

int main () {
    if (SQLite::Initialize ()) {
        try {
            if (database.open (L"test.db")) {
                
                // simple statements
                database.execute (L"CREATE TABLE `test` (`a` INTEGER PRIMARY KEY NOT NULL, `b` INTEGER NOT NULL)");
                database.execute (L"INSERT INTO `test` VALUES (1, 112)");
                
                // prepared statements
                auto insert = database.prepare (L"INSERT INTO `test` VALUES (?, ?)");
                
                // binding more than one parameter
                insert.execute (2, 233);

                // binding more than one parameter
                insert.reset ();
                insert.bind (3, 334);
                insert.execute ();
                
                // binding each parameter with a call
                insert.reset ();
                insert.bind (4);
                insert.bind (445);
                insert.execute ();

                // single value query, result is '3'
                printf ("%d\n", database.query <int> (L"SELECT ?+?", 1, 2));
                
                // full query
                auto query = database.prepare (L"SELECT `a`, `b` FROM `test` ORDER BY `a` ASC");
                while (query.next ()) {
                    printf ("%d '%ls'\n",
                            query.get <int> (L"a"), // getting value of column 'a' as int
                            query.get <std::wstring> (1) .c_str ()); // getting value of second column as string
                }

                database.execute (L"DROP TABLE `test`");
            } else {
                printf ("open error: \n");
            }
        } catch (const SQLite::Exception & x) {
            printf ("exception: %s\n", x.what ());
        }
        SQLite::Terminate ();
    }
    return 0;
}

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.