The SQLoco Book (Preliminary Documentation)

A C++ Wrapper for SQL LibrariesTemplate Scripting language for C++

Isaac W. Foraker

Abstract

This is documentation for SQLoco, a C++ wrapper for SQL libraries. For the most up to date documentation, go to http://tazthecat.net/~isaac/sqloco/.


Table of Contents

Introduction
What is SQLoco?
Why SQLoco?
A quick example
1. Compilation and Installation
Supported Platforms/Compilers
Where to get SQLoco
Building on Windows
Building on Unix
A. Project Specifics
License
Credits
Reporting bugs

Introduction

What is SQLoco?

SQLoco is a C++ wrapper for SQL libraries. The goal is to have a simple, uniform interface for accessing any SQL library on any platform that supports standard C++. This early release will focus on MySQL and later on PostgreSQL. Contributors are welcome to add support for other databases, and feedback is welcome.

SQLoco is modeled on the DBI module used with Perl. This is done to simplify learning the SQLoco interface, though there are some differences from the Perl module. This source is released under a BSD style license, which means it is free as long as you credit the original authors.

Why SQLoco?

There are currently many libraries that deal with accessing SQL servers. Every time I would switch platforms, I found myself learning a new library. SQLoco is intended to provide an easy to learn, free interface to any database.

A quick example

Assuming your application has already opened a connection to the database, an accessor function may look like this:

void myFunc(sqloco::dbi& dbh, std::string param)
{
	sqloco::statement* sth;

	sth = dbh.prepare(
		"SELECT		column1, column2, column3\n"
		"FROM		mytable\n"
		"WHERE		column4=?\n"
		"ORDER BY	column1\n"
		);
	sth->addparam(param);
	if (sth->execute() < 0)
	{
		std::cerr << "Error: " << dbh.errstr() << std::endl;
		delete sth;
		return;
	}
	sqloco::Hash hash;
	while (!sth->fetchhash(hash))
	{
		std::cout << hash["column1"] << ", " << hash["column2"]
			<< ", " << hash["column3"] << std::endl;
	}
	delete sth;
}

Chapter 1. Compilation and Installation

Supported Platforms/Compilers

SQLoco has been compiled and tested on the following platforms. This should not be considered a definitive list since SQLoco is designed to be portable.

FreeBSD 4.6 GCC 3.2
OS X 10.1 GCC 3.1 (Apple version 1041)

SQLoco should build on any platform that supports GCC 3.1.1. The Microsoft Visual C++ 7 compiler will also be supported.

Building on Windows

SQLoco is being written with MSVC++ 7 (aka .Net) in mind. At the time of this writing, project files are not yet available. SQLoco should build under the Cygwin environment using the Unix build instructions.

Building on Unix

SQLoco will build with GCC 3.1 or greater. Early versions of GCC (i.e. 2.95.x) are not supported.

The configure.pl script will attempt to automatically identify which SQL libraries you have installed. In case it fails, you must specify the locations of the libraries manually. Use the --help option for instructions.

				./configure.pl [--help]
				make
				(as root)
				make install
			

By default, configure.pl will use /usr/local as the install directory, placing files in /usr/local/lib and /usr/local/include. Use --prefix=/your/install/path to override this.

Appendix A. Project Specifics

License

SQLoco - A C++ wrapper for SQL libraries.
Copyright (C) 2002-2003 Isaac W. Foraker (isaac(at)tazthecat(dot)net)
All Rights Reserved

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  3. Neither the name of the Author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Credits

SQLoco Design, Programming and Documentation

  • Isaac W. Foraker (http://tazthecat.net/~isaac/)

Contributors

  • None yet

Reporting bugs

If you encounter a bug in the SQLoco, please send an e-mail to isaac(at)tazthecat(dot)net.