4
 * Copyright (C) 2015 Tim Marston <tim@ed.am>
 
 
6
 * This file is part of sqlite3cc (hereafter referred to as "this program").
 
 
7
 * See http://ed.am/dev/sqlite3cc for more information.
 
 
9
 * This program is free software: you can redistribute it and/or modify it under
 
 
10
 * the terms of the GNU Lesser General Public License as published by the Free
 
 
11
 * Software Foundation, either version 3 of the License, or (at your option) any
 
 
14
 * This program is distributed in the hope that it will be useful, but WITHOUT
 
 
15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
 
16
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
 
 
19
 * You should have received a copy of the GNU Lesser General Public License
 
 
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
23
#include <sqlite3cc.h>
 
 
24
#include <boost/filesystem.hpp>
 
 
27
#define DBFILE "blob.db"
 
 
32
        // delete any existing test database
 
 
33
        if( boost::filesystem::exists( DBFILE ) )
 
 
34
                boost::filesystem::remove( DBFILE );
 
 
37
        sqlite::connection conn( DBFILE );
 
 
39
        std::cout << "SQLite threading mode: " << sqlite::threadsafe() << "\n";
 
 
42
        sqlite::command c1( conn,
 
 
43
                "CREATE TABLE test ( "
 
 
44
                        "name TEXT PRIMARY KEY, "
 
 
49
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
 
51
        // insert data in to blob
 
 
53
                'h', 'e', 'l', 'l', 'o', 0,
 
 
54
                't', 'h', 'e', 'r', 'e'
 
 
56
        std::string str( data, sizeof( data ) );
 
 
57
        size_t length = str.length();
 
 
58
        std::cout << "data size: " << length << " chars\n";
 
 
59
        sqlite::command( conn, "INSERT INTO test VALUES( ?, ? )" )
 
 
60
                << "test" << sqlite::blob( str ) << sqlite::exec;
 
 
62
        // check that it is stored in its entirety
 
 
63
        sqlite::query q1( conn, "SELECT length( data ) FROM test" );
 
 
64
        assert( q1.step().column< int >( 0 ) == length );
 
 
66
        // retrieve data from blob
 
 
67
        sqlite::query q2( conn, "SELECT data FROM test" );
 
 
68
        std::string str2 = q2.step().column< std::string >( 0 );
 
 
69
        assert( str2 == str );