29 lines
836 B
Python
29 lines
836 B
Python
from cfg import config
|
|
|
|
def _get_page_id(title, connection):
|
|
cursor = connection.cursor()
|
|
if(config["use_sqlite"]):
|
|
cursor.execute("SELECT rowid FROM pages WHERE title=%s", (title,))
|
|
else:
|
|
cursor.execute("SELECT page_id FROM pages WHERE title=%s", (title,))
|
|
return cursor.fetchone()
|
|
|
|
def get_page_id(title, connection):
|
|
|
|
result = _get_page_id(title, connection)
|
|
if(result is not None):
|
|
return result[0]
|
|
|
|
cursor = connection.cursor()
|
|
cursor.execute("INSERT INTO pages(title) VALUES(%s)", (title,))
|
|
return _get_page_id(title, connection)[0]
|
|
|
|
def get_page_title(page_id, connection):
|
|
cursor = connection.cursor()
|
|
if(config["use_sqlite"]):
|
|
cursor.execute("SELECT title FROM pages WHERE rowid=%s", (page_id,))
|
|
else:
|
|
cursor.execute("SELECT title FROM pages WHERE page_id=%s", (page_id,))
|
|
return cursor.fetchone()[0]
|
|
|