-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
90 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,82 @@ | ||
import de.bezier.data.sql.*; | ||
import java.sql.SQLException; | ||
|
||
|
||
class skDB { | ||
|
||
private SQLite db; | ||
|
||
skDB(PApplet pa, String database) { | ||
|
||
SQLite db = new SQLite( pa, database ); // open database file | ||
db = new SQLite( pa, database ); // open database file | ||
|
||
if ( db.connect() ) | ||
{ | ||
// list table names | ||
db.query( "SELECT name as \"Name\" FROM SQLITE_MASTER where type=\"table\"" ); | ||
|
||
while (db.next()) | ||
{ | ||
println( db.getString("Name") ); | ||
} | ||
|
||
// read all in table "table_one" | ||
db.query( "SELECT * FROM table_one" ); | ||
|
||
while (db.next()) | ||
{ | ||
println( db.getString("field_one") ); | ||
println( db.getInt("field_two") ); | ||
|
||
try { | ||
|
||
db.statement = db.connection.createStatement(); | ||
db.statement.setQueryTimeout(1); | ||
|
||
//printListTables(); | ||
// printTimestamps(); | ||
//printTimestampsLondon(); | ||
|
||
|
||
} catch(SQLException e) { | ||
println(e.getMessage()); | ||
} | ||
} | ||
} | ||
|
||
void query(String q) { | ||
db.query(q); | ||
} | ||
|
||
private void printListTables() { | ||
// list table names | ||
db.query( "SELECT name as \"Name\" FROM SQLITE_MASTER where type=\"table\"" ); | ||
|
||
while (db.next()) { | ||
println( db.getString("Name") ); | ||
} | ||
} | ||
|
||
private void printTimestamps() { | ||
long cnt = 0; | ||
|
||
db.query( "SELECT ts FROM sk_data AS s LIMIT 10000" ); | ||
|
||
while (db.next()) | ||
{ | ||
println(getTimestamp("ts")); | ||
cnt++; | ||
} | ||
println(cnt + " records."); | ||
} | ||
|
||
private void printTimestampsLondon() { | ||
long cnt = 0, st, el; | ||
|
||
|
||
st = System.currentTimeMillis(); | ||
db.query( "SELECT * from sk_data as s LEFT JOIN ip_group_city as i ON s.ip_start=i.ip_start WHERE i.city LIKE 'London'" ); | ||
el = System.currentTimeMillis() - st; | ||
println(String.format("Query runtime = %d min %02d.%03d sec", el/1000/60, (el / 1000) % 60 , el % 1000)); | ||
|
||
st = System.currentTimeMillis(); | ||
while (db.next()) | ||
{ | ||
// println(getTimestamp("ts")); | ||
cnt++; | ||
//if (cnt % 1000 == 0) println(cnt + "..."); | ||
} | ||
println(cnt + " records."); | ||
el = System.currentTimeMillis() - st; | ||
println(String.format("Loop through runtime = %d min %02d.%03d sec", el/1000/60, (el / 1000) % 60 , el % 1000)); | ||
} | ||
|
||
Date getTimestamp(String field) { | ||
return new Date(db.getLong("ts") * 1000); | ||
} | ||
} |