38 lines
852 B
Plaintext
38 lines
852 B
Plaintext
|
use jdbc
|
||
|
|
||
|
conn = getConnection("jdbc:sqlite:danboo.db")
|
||
|
|
||
|
st = conn.createStatement()
|
||
|
st.executeUpdate(
|
||
|
"CREATE TABLE IF NOT EXISTS meta (
|
||
|
prop TEXT PRIMARY KEY,
|
||
|
num_value INTEGER,
|
||
|
str_value TEXT
|
||
|
)")
|
||
|
st.executeUpdate(
|
||
|
"INSERT OR IGNORE INTO meta(prop, num_value, str_value) VALUES('last_id', 0, '')")
|
||
|
st.close()
|
||
|
|
||
|
stGetNumValue = conn.prepareStatement(
|
||
|
"SELECT num_value FROM meta WHERE prop = ?")
|
||
|
stSetNumValue = conn.prepareStatement(
|
||
|
"UPDATE meta SET num_value = ? WHERE prop = ?")
|
||
|
|
||
|
def getLastPostId() {
|
||
|
stGetNumValue.setString(1, "last_id")
|
||
|
rs = stGetNumValue.executeQuery()
|
||
|
return rs.getInt(1)
|
||
|
}
|
||
|
|
||
|
def setLastPostId(postId) {
|
||
|
stSetNumValue.setInt(1, postId)
|
||
|
stSetNumValue.setString(2, "last_id")
|
||
|
stSetNumValue.executeUpdate()
|
||
|
}
|
||
|
|
||
|
def closeDB() {
|
||
|
stGetNumValue.close()
|
||
|
stSetNumValue.close()
|
||
|
conn.close()
|
||
|
}
|