Friday, February 15, 2008

Don't Be Afraid!

"Learning By Doing" is a wonderful technique for many people. If the documentation isn't perfectly clear, or if the examples don't match your requirements, just writing some code and seeing what happens is often the best approach.

Fear, however, sometimes stands in the way of Learning By Doing:

  • Fear that your experimentation will disturb a critically-important development or production environment, and

  • Fear that setting up a separate test-bed will be difficult and time-consuming.
The first fear is often rational and justified. So is the second fear, if you're talking about Oracle or SQL Server or DB2, but not if you're using SQL Anywhere.

With SQL Anywhere, you can create and launch a new database on your workstation in a matter of seconds, and start your Learning By Doing adventure with no effect on anyone else. The software you use will be exactly the same as the version used in production, nothing "Lite" about it, so your experimental results will be meaningful.

Here is the Windows batch file that I regularly use to create and/or start an experimental database. The dbinit utility creates the database file ddd10.db, the dbspawn/dbeng10 step starts the database, and the last two commands start two dbisql sessions with "ddd10-1" and "ddd10-2" showing in the window title bars so they're easy to tell apart.



(Caution: The last 3 commands should each appear on a single line, but each one has been "wrapped" onto two lines to fit on the screen.)
REM dbinit...
REM -e simple encryption
REM -et enable table encryption
REM -s use checksums when writing pages

REM dbspawn...
REM -f do not check for a running server.
REM -q quiet mode — do not print messages.

REM dbeng10...
REM -c ... initial RAM cache size
REM -o ... where to put server console log text file
REM -os 10M when to rename/restart console log text file
REM -x none only allow "shared memory" client connections
REM -z diagnose communication links
REM -zl RememberLastStatement for LastStatement
REM -zp RememberLastPlan for LastPlanText
REM -zt RequestTiming for performance statistics
REM ddd.db first database to start

REM dbisql...
REM -c ... database connection string

"%SQLANY10%\win32\dbinit.exe" -et -s ddd10.db

"%SQLANY10%\win32\dbspawn.exe" -f "%SQLANY10%\win32\dbeng10.exe"
-o dbeng10_log_ddd10.txt -os 10M -x tcpip -zl -zp -zt ddd10.db

"%SQLANY10%\win32\dbisql.exe"
-c "ENG=ddd10;DBN=ddd10;UID=dba;PWD=sql;CON=ddd10-1"

"%SQLANY10%\win32\dbisql.exe"
-c "ENG=ddd10;DBN=ddd10;UID=dba;PWD=sql;CON=ddd10-2"
You can run the batch file whether or not the ddd10.db file already exists, and whether or not the engine is already running. If the database file already exists, the dbinit step will just display an error message and move to the next step. If the engine is already running, dbspawn/dbeng10 will display an error and move on to the dbisql steps.

That means if all you need is to restart an existing database, or start a dbisql session on a running database, you can run this batch file; you don't need to do something different.

And best part is this: If your experimentation runs completely awry and you want to start over, here's all you have to do:
  • Stop the engine,

  • Delete the files ddd10.db and ddd10.log, and

  • Run the batch file again.

No comments: