C#
C++
SQL

SQLite Quick Reference

The homepage for SQLite claims that it is the most deployed widely SQL database in the world. I don't know if that is true but SQLite is a powerful light-weight SQL database.
http://sqlite.org/

I discovered this library while I was talking to some folks on IRC (#C++ on EFNET). I was working on the Kahnadex Jukebox program at the time and needed a "default" database. The first version of the program I wrote required the MSDE to be installed which was way too heavy / hard to configure for end users. I dug into SQLite (version 3.x) and one immediate downside was that I had to get the source code and hack around before I could use it. Even though the documentation wasn't great I was pleased with the result.

Setup
Start off by just downloading the DLL. On the download page grab the version for Windows that says "This is a DLL of the SQLite library without the TCL bindings". After downloading the zip, you'll notice there is only a .DLL and a .DEF file. You'll need a header and a .lib file in order to compile against the DLL.

Open up the Visual Studio command prompt and navigate to the folder you unzipped the DLL/DEF to. You can then run this command:
lib /machine:i386 /def:sqlite3.def
This will generate the .lib and .exp for the DLL. What I did to find the header is download the source code for the library itself. I grabbed the "sqlite3.h" header file from the source code that was grouped as "individual source files". Once you grab the header just add the link to the .lib file in your compiler and you're ready.

Opening and closing the database
#include "sqlite3.h"

sqlite3* db;

if(sqlite3_open("my_database.db",&db)){
    printf("Can't open database: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    //handle error here...
}

When you're done using the database, close it using:
sqlite3_close(db);
Executing Non-Queries
std::string sql = "UPDATE Song SET AlbumID = NULL;";

if(sqlite3_exec(db,sql.c_str(),0,0,0)){
    printf("Failed to update rows: %s\n",sqlite3_errmsg(db));
    //handle error here...
}

Executing Queries (SELECTing data)
Executing SELECT queries in SQLite is pretty horrible in my opinion. You execute it the same way as you do a non-query, except you will need to use the callback parameter.

//SQLite DB, SQL query, callback function name, data to pass to callback, error msg
sqlite3_exec(db,sql_query_here,callback_here,NULL,0);

//this callback gets called for EVERY ROW returned by the query
int SampleCallback(void* SpecialData,int argc,char **argv,char** ColumnName){
    //returned record is in argv
    //column names are in ColumnName
    //the SpecialData is a pointer which you can optionally pass in the exec statement
    int SongID = atoi(argv[0]);
    std::string SongName = std::string(argv[1]);
    return(0);
}

Other notes
In my experience SQLite is pretty slow. If you're after performance you'll definitely want to choose MS SQL Server, Oracle, or MySQL. SQLite only allows for one "connection" so to speak. You'll want to wrap a mutex around your DB calls or else you'll get unexpected behavior.

If you're a big MS SQL Server programmer like I am, you are probably used to getting the ID of the entry you just inserted. This is possible in SQLite. For example, if I insert a Song into my database and I want to get the identity of the Song entry that was just inserted... in SQL Server (in a stored procedure) you would use SCOPE_IDENTITY(). I had to ask around and then I found the SQLite function:
int myRowId = sqlite3_last_insert_rowid(db);

Labels: , ,

posted by Brian at | 0 Comments

 

CVS Quick Reference

Useful Commands
Initial check-out
cvs co -r branch_name module_name
Protip: the -r specifies that you want to checkout from a tag/branch.

Branching
cvs tag -b branch_name

Get latest
cvs up -Pd
Protip: the P prunes empty directories and the d will cause directories to be created as needed.

Commit / check-in changes
cvs commit
Protip: Always do a cvs up before you commit. Running cvs up will automatically merge if needed. Then you can view the merge (if one occured) and manually disposition it.

Adding /removing a file
cvs add file.txt
cvs delete file.txt
Protip: After adding or deleting a file you must commit the change in order for it to be visible to other users.

Checking differences against a branch
cvs diff -r branch_name
Protip: In my opinion, using Tortoise CVS with WinMerge is much easier than the command line cvs diff tool.

Merging a branch
cvs up -j branch_name -Pd
Protip: the j is what actually causes the merge to happen (merges changes made between working directory and the branch you provide).

When all else fails
cvs --help-options
cvs up --help-options
cvs co --help-options
cvs diff --help-options

What the letters mean when doing a CVS update
U - updated successfully
A - added but not yet committed (need to run a cvs commit)
R - removed but not yet committed (need to run a cvs commit)
M - modified in your working directory: the file in the repository was changed and your working directory file was older than the last time CVS checked it OR the repository had changes which the system could safely merge
C - there was a conflict between the repository copy and your copy which requires human intervention
? - the file is in your working directory but not the repository and CVS doesn't know what to do with it

The format of CVSROOT
The CVSROOT is basically your connection string to the source repository. These are your credentials to login to CVS. The CVSROOT is in this format:
:pserver:username@computer_name:repository

Downloads
Tortoise CVS - a Windows shell integration interface for CVS
http://www.tortoisecvs.org/

WinMerge - a diff utility. Integrates with Tortoise
http://winmerge.org/

Labels:

posted by Brian at | 0 Comments

 

Windows Command Line Quick Reference

Basic DOS commands / tools

mkdirmake a directory
cdchange directory
cd \go to root of the current drive
ipconfigview ip address or release/renew address via DHCP
xcopycopy files
deldelete files
setview /set environment variables
dirview files in a directory
runasrun an executable as a different user

Useful windows commands / tools (use these from the run box)
appwiz.cplthe add/remove program control panel
cmdopen a DOS prompt
desk.cplthe display control panel
eventvwrevent viewer
isqlwSQL Query Analyzer (if you have SQL Server 2000 installed)
mstscterminal services / remote desktop client
regeditregistry editor
services.mscthe services admin tool
taskmgrtask manager
tsadminterminal services admin
exploreropen a new explorer window

Less useful commands / tools
calcwindows calculator
confnet meeting
oskon screen keyboard
pbrushpaintbrush art program
sndrec32windows sound recorder
wmplayerwindows media player
winwordMicrosoft Word

Labels: ,

posted by Brian at | 0 Comments