# In all of the following statements, the '{0}' variable represents the table name

# The statement that creates the table.
create_table = CREATE TABLE {0} ( \
                 cid VARCHAR(255) NOT NULL, \
                 mime_type VARCHAR(255), \
                 ext_text VARCHAR(1000), \
                 usage_flag INTEGER, \
                 usage_time TIMESTAMP, \
                 payload LONGBLOB, \
                 primary key(cid) \
               )

# The query that is used to determine if the table already exists by returning any result set.
table_exists_query = SELECT COUNT(*) FROM {0}

# Insert a new binary value into the table
add_content = INSERT INTO {0} (cid, usage_time, payload, usage_flag) VALUES ( ?,?,?,1 )

# Get the content for the binary with the supplied key
get_used_content = SELECT payload FROM {0} WHERE cid = ? AND usage_flag=1
get_unused_content = SELECT payload FROM {0} WHERE cid = ? AND usage_flag=0

# Mark the binary with the specified key as being unused
mark_unused = UPDATE {0} SET usage_flag=0, usage_time = ? WHERE cid = ?

# Mark the binary with the specified key as being used
mark_used = UPDATE {0} SET usage_flag=1 WHERE cid = ?

# Remove all rows that have been unused for less than the supplied time
remove_expired = DELETE FROM {0} WHERE usage_time < ? AND usage_flag=0

# Get the MIME type for the binary with the specified key
get_mimetype = SELECT mime_type FROM {0} WHERE cid = ?

# Set the MIME type for the binary with the specified key
set_mimetype = UPDATE {0} SET mime_type = ? WHERE cid = ?

# Get the text that was extracted from the binary with the specified key
get_extracted_text = SELECT ext_text FROM {0} WHERE cid = ?

# Set the text that was extracted from the binary with the specified key
set_extracted_text = UPDATE {0} SET ext_text = ? WHERE cid = ?

# Get all of the binary keys
get_binary_keys = SELECT cid FROM {0} WHERE usage_flag = 1
