Is there an easy way to control indents in Python

Juan Christian juan0christian at gmail.com
Mon Oct 20 18:30:35 EDT 2014


Sorry guys, my post about SQL was not meant to be here!!!

On Mon, Oct 20, 2014 at 5:43 PM, MRAB <python at mrabarnett.plus.com> wrote:

> On 2014-10-20 20:04, Juan Christian wrote:
>
>> 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, url, author, message):
>>      db.execute("INSERT INTO TOPICS (ID, URL, AUTHOR, MESSAGE) VALUES
>> (?, ?, ?, ?)", (_id, url, author, message))
>>      db.commit()
>>
>>
>> def get_db(_id):
>> cursor = db.execute("SELECT ID, URL, AUTHOR, MESSAGE FROM TOPICS WHERE
>> ID = ?", (_id))
>> return cursor.fetchone()
>>
>>
>> if __name__ == '__main__':
>> create_db()
>> insert_db(12, 'abc.com <http://abc.com>', 'a', 'b')
>> print(get_db(12))
>> db.close()
>>
>> -------------
>>
>> But now when I execute I get
>>
>> Traceback (most recent call last):
>>    File ".\sql.py", line 30, in <module>
>>      print(get_db(12))
>>    File ".\sql.py", line 23, in get_db
>>      cursor = db.execute("SELECT ID, URL, AUTHOR, MESSAGE FROM TOPICS
>> WHERE ID = ?", (_id))
>> ValueError: parameters are of unsupported type
>>
>> -------------
>>
>>  I'm not certain, but I think that the SQL type is called "INTEGER", not
> "INT".
>
>  And the second time, again, I get
>>
>> Traceback (most recent call last):
>>    File ".\sql.py", line 28, in <module>
>>      create_db()
>>    File ".\sql.py", line 14, in create_db
>>      ''')
>> sqlite3.OperationalError: table TOPICS already exists
>>
>>  That's because you created the table the last time you ran it.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141020/b36c6ee0/attachment.html>


More information about the Python-list mailing list