Re: [Tutor] Python sqlite3 issue

2014-10-22 Thread Alan Gauld
On 22/10/14 23:30, Juan Christian wrote: The only thing left now is that the topics in this forum has a one/two weeks lifespan, and I think Steam reuses the same ID for new topics that was used in, lets say a 1 month-old topic In that case I'd go back to using a primary key ID set by SQLite an

Re: [Tutor] Python sqlite3 issue

2014-10-22 Thread Juan Christian
On Wed, Oct 22, 2014 at 4:37 PM, Alan Gauld wrote: > > Incidentally you don't need the semi-colon inside the execute. It can only > execute the entire string so if there's only one command you > don't need the terminator. Ok, thanks! Note that this makes no checks for unique ID so you put the

Re: [Tutor] Python sqlite3 issue

2014-10-22 Thread Alan Gauld
On 22/10/14 18:38, Juan Christian wrote: def ini_db(): db.execute(''' CREATE TABLE IF NOT EXISTS TOPICS( ID INTEGER NOT NULL, URL VARCHAR NOT NULL, AUTHOR VARCHAR NOT NULL, MESSAGE VARCHAR NOT N

Re: [Tutor] Python sqlite3 issue

2014-10-22 Thread Juan Christian
So guys, now I have this code that is fully working: import sqlite3 db = sqlite3.connect('db.sqlite') def ini_db(): db.execute(''' CREATE TABLE IF NOT EXISTS TOPICS( ID INTEGER NOT NULL, URL VARCHAR NOT NULL, AUTHOR VAR

Re: [Tutor] Python sqlite3 issue

2014-10-21 Thread Alan Gauld
On 21/10/14 09:18, Peter Otten wrote: Another option is to only create the table if it does not already exist: create table if not exists topics ... The danger with that one is that if you are changing the structure of the table you can wind up keeping the old structure by accident and your

Re: [Tutor] Python sqlite3 issue

2014-10-21 Thread Peter Otten
Alan Gauld wrote: > Finally when creating tables you can use: > > DROP TABLE IF EXISTS TOPICS; > > Prior to creating it. That will ensure you don't get an existing > table error. Another option is to only create the table if it does not already exist: create table if not exists topics ... __

Re: [Tutor] Python sqlite3 issue

2014-10-20 Thread Alan Gauld
On 20/10/14 18:04, Juan Christian wrote: What's the problem? It's just a test script just to learn sqlite3 with python. If you are learning SQLite3 as well as how to access it from Python I strongly recommend installing the sqlite3 interpreter and typing the SQL commands directly into that.

Re: [Tutor] Python sqlite3 issue

2014-10-20 Thread Alan Gauld
On 20/10/14 18:04, Juan Christian wrote: CREATE TABLE TOPICS( ID INT PRIMARY KEY NOT NULL, This means SQLite will automatically create the ID value, you do not need to provide one. URL VARCHAR NOT NULL, AUTHOR VARCHAR NOT NULL, MESSAGE VARCHAR NOT NULL ); ''') def insert_db(_id, url, auth

Re: [Tutor] Python sqlite3 issue

2014-10-20 Thread Juan Christian
Ok, new code using ?: import sqlite3 db = sqlite3.connect('db.sqlite') def create_db(): db.execute(''' CREATE TABLE TOPICS( ID INT PRIMARY KEY NOT NULL, URL VARCHAR NOT NULL, AUTHOR VARCHAR NOT NULL, MESSAGE VARCHAR NOT NULL ); ''') def insert_db(_id, ur

Re: [Tutor] Python sqlite3 issue

2014-10-20 Thread Danny Yoo
insert_db(12, "abc.com", "author", "message") > INSERT INTO TOPICS (ID, URL, AUTHOR, MESSAGE) VALUES (12, abc.com, > author, message) > > I've never used format like that. It looks like you need to quote the > strings. I don't know if you can tell format to do that or if you > have to e

Re: [Tutor] Python sqlite3 issue

2014-10-20 Thread Joel Goldstick
On Mon, Oct 20, 2014 at 1:04 PM, Juan Christian wrote: > I have this code (http://pastebin.com/Q21vQdHZ): > > import sqlite3 > > db = sqlite3.connect('db.sqlite') > > > def create_db(): > db.execute(''' > CREATE TABLE TOPICS( > ID INT PRIMARY KEY NOT NULL, > URL VARCHAR NOT NULL, >

Re: [Tutor] Python sqlite3 issue

2014-10-20 Thread Danny Yoo
Hi Juan, On Mon, Oct 20, 2014 at 10:04 AM, Juan Christian wrote: > I have this code (http://pastebin.com/Q21vQdHZ): > > import sqlite3 [code cut] > def insert_db(_id, url, author, message): > db.execute("INSERT INTO TOPICS (ID, URL, AUTHOR, MESSAGE) VALUES ({}, > {}, {}, {})".format(_id,

[Tutor] Python sqlite3 issue

2014-10-20 Thread Juan Christian
I have this code (http://pastebin.com/Q21vQdHZ): import sqlite3 db = sqlite3.connect('db.sqlite') def create_db(): db.execute(''' CREATE TABLE TOPICS( ID INT PRIMARY KEY NOT NULL, URL VARCHAR NOT NULL, AUTHOR VARCHAR NOT NULL, MESSAGE VARCHAR NOT NULL ); ''') d