Anonymous user
Table creation/Postal addresses: Difference between revisions
→{{header|AWK}}: Added AWK + SQLite version.
(→Apache Derby: fix typo.) |
(→{{header|AWK}}: Added AWK + SQLite version.) |
||
Line 121:
</pre>
=={{header|AWK}}==
=== SQLite3 ===
This version uses the AWK pipe and 'getline' function to use the sqlite3 command line program.
<lang awk>#!/bin/sh -f
awk '
BEGIN {
print "Creating table...";
dbExec("address.db", "create table address (street, city, state, zip);");
print "Done.";
exit;
}
function dbExec(db, qry, result) {
dbMakeQuery(db, qry) | getline result
dbErrorCheck(result);
}
function dbMakeQuery(db, qry, q) {
q = dbEscapeQuery(qry) ";";
return "echo \"" q "\" | sqlite3 " db
}
function dbEscapeQuery(qry, q) {
q = qry;
gsub(/"/, "\\\"", q);
return q;
}
function dbErrorCheck(res) {
if (res ~ "SQL error") {
print res;
exit;
}
}
'</lang>
=={{header|C}}==
|