[SparForte][Banner]
[Top Main Menu] Intro | Tutorials | Reference | Packages | Examples | Contributors   [Back Page]      [Next Page]  

Database Commands

SparForte understands basic SQL commands.  This feature is a great convenience for people who work frequently with databases.  The SQL command parameters are given directly to your database.  SparForte recognizes the following SQL commands:

  • alter - alter a database table
  • delete - delete a row from a database table
  • insert - add a row to a database table
  • select - show the results of a database query
  • update - edit a row in a database table

SQL is a different language from AdaScript and the Bourne shell.  SQL for one database may not be compatible with another.  For example, an asterisk (*) will not expand to a list of files and quote marks indicate strings or table names, not how to expand dollar variables.  Your database documentation will explain how to use your version of SQL.

SparForte submits the SQL command to the database with only one change.  Bush will search command for variables and will substitute values using a dollar sign ($) and escape characters with a backslash.  Single and double quotes have no effect on how the variable is substituted since quote marks used for a different purpose in SQL.

Like a shell command, the output from the database commands can be redirected or captured using backquotes.  The commands can be intermixed with the db package database commands.

For example,

=> db.connect( "ken" )
=> select * from users
 name  | age
-------+------
 ken   | 38
 dan   | 37
 chris | 40
 kati  | 36
 4 Rows and 2 Columns
=> select * from users where user \> 'dan'
 name  | age
-------+------
 ken   | 38
  kati  | 36
  2 Rows and 2 Columns
=> select count(*) from users > temp.tmp
=> cat temp.tmp
 count
-------
 4
=> s : string := `select age from users;`
=>  k := "ken"
=> (Assuming k is a new universal_string variable)
=> select * from users where name = '$k'
 name | age
------+------
 ken  | 38
=> db.disconnect
 

Example: Examples of Database Commands

The format of select statements is the same as db.show in the db package.

Some limitations on database commands:

  • Database commands cannot (yet) be used in a pipeline
  • SparForte interprets <, >, >>, $, quotes and other symbols (escape them when necessary using \)
  • Database commands cannot be used with pragma ada_95 (use the db library instead)

[Right Submenu]

 AdaScript versus GCC

 Case Sensitivity

 Reserved Words

 Comments

 Literals

 Bourne Shell Word Expansions

 Fundamental Types

 User-defined Types

 Enumerated Types

 Arrays

 Records

 Basic Assignment

 The @ and % Operands

 Command Argument Shortcuts

 Redirection and Pipelines

 Command Line Interaction

 Built-in Shell Commands

 The Current Directory

 Database Commands

 Flow of Control

 Other Statements/ Subprograms

 External Commands

 Block Statements and Subprograms

 TCP/IP Sockets

 Numeric Formatting with Put

 Interpreter Directives

 Command Line Options

 Command Reference

 ASCII and Latin_1 Character Sets

 Common Error Messages

 Common PHP Functions and the SparForte Equivalent

[Back to Top] Back To Top [Small Forte Symbol]