I'm trying to add a row (post submitted by user) into a SQLite table (posts). I need to add the new post with the timestamp being the current time and date and then i need to return the id for this new post.
My code so far (incomplete as im not sure how to return the id and if im inserting the right info):
def post_add(conn, username, message):
cursor = conn.cursor()
cursor.execute("INSERT INTO posts (timestamp, username, message) VALUES (CURRENT_TIMESTAMP,?,?)"
, (username, message))
db.commit()
The table:
CREATE TABLE posts (
id integer unique primary key autoincrement,
timestamp text default CURRENT_TIMESTAMP,
username text,
message text,
FOREIGN KEY(username) REFERENCES users(name)
);