Data update

This commit is contained in:
Ingy dot Net 2024-04-19 16:56:29 -07:00
parent 0df55f9f24
commit aec8ed51b6
1045 changed files with 18889 additions and 2777 deletions

View file

@ -0,0 +1,18 @@
# create a new database file or open it
dbopen "addresses.sqlite3"
# delete the existing table - If it is a new database, the error is captured
onerror errortrap
dbexecute "drop table addresses;"
offerror
# create the table
dbexecute "CREATE TABLE addresses (addrID integer, addrStreet string, addrCity string, addrState string, addrZIP string);"
# close all
dbclose
end
errortrap:
# accept the error - show nothing - return to the next statement
return

View file

@ -0,0 +1,31 @@
#include once "sqlite3.bi"
Const NULL As Any Ptr = 0
Dim As sqlite3 Ptr db
Dim As zstring Ptr errMsg
If sqlite3_open(":memory:", @db) <> SQLITE_OK Then
Print "Could not open database: "; sqlite3_errmsg(db)
sqlite3_close(db)
Sleep
End 1
End If
Dim As String sql = "CREATE TABLE address(" _
& "addrID INTEGER PRIMARY KEY AUTOINCREMENT," _
& "addrStreet TEXT NOT NULL," _
& "addrCity TEXT NOT NULL," _
& "addrState TEXT NOT NULL," _
& "addrZIP TEXT NOT NULL);"
If sqlite3_exec(db, sql, NULL, NULL, @errMsg) <> SQLITE_OK Then
Print "Error creating table: "; *errMsg
sqlite3_free(errMsg)
Else
Print "Table created successfully"
End If
sqlite3_close(db)
Sleep

View file

@ -0,0 +1,41 @@
import "./table" for Table, FieldInfo, Records
var fields = [
FieldInfo.new("id", Num),
FieldInfo.new("name", String),
FieldInfo.new("street", String),
FieldInfo.new("city", String),
FieldInfo.new("state", String),
FieldInfo.new("zipCode", String)
]
// create table
var table = Table.new("Addresses", fields)
// add records in unsorted order
table.addAll([
[2, "FSF Inc.", "51 Franklin Street", "Boston", "MA", "02110-1301"],
[1, "The White House", "The Oval Office 1600 Pennsylvania Avenue NW", "Washington", "DC", "20500"],
[3, "National Security Council", "1700 Pennsylvania Avenue NW", "Washington", "DC", "20500"]
])
var colWidths = [2, 25, 43, 10, 2, 10] // for listings
// show the table's fields
table.listFields()
System.print()
// sort the records by 'id' and show them
var sortFn = Fn.new { |s, t| s[0] < t[0] }
var records = table.sortedRecords(sortFn)
Records.list(table.fields, records, "Records for %(table.name) table:\n", colWidths)
// find a record by key
System.print("\nThe record with an id of 2 is:")
System.print(table.find(2))
// delete a record by key
table.remove(1)
System.print("\nThe record with an id of 1 will be deleted, leaving:\n")
records = table.sortedRecords(sortFn)
Records.list(table.fields, records, "Records for %(table.name) table:\n", colWidths)