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
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
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
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
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
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 ...
__
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.
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
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
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
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,
>
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,
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
13 matches
Mail list logo