('Successfully Created Tables!')Ĭreate_chatroom('Lobby', 'Insight is the future', cur, con) #create the message room for the name of the room you are creating.Ĭur.execute("""CREATE TABLE %s (ID INTEGER PRIMARY KEY AUTOINCREMENT,Ĭur.execute("""CREATE TABLE ROOMS(ID INTEGER PRIMARY KEY AUTOINCREMENT,Ĭur.execute("""CREATE TABLE USERS(ID INTEGER PRIMARY KEY AUTOINCREMENT,Ĭur.execute("""CREATE TABLE FRIENDS(ID INTEGER PRIMARY KEY AUTOINCREMENT, # See the License for the specific language governing permissions andįrom multiprocessing import Pool, Processįrom import Outputĭef create_chatroom(name, tagline, cur, conn): # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # distributed under the License is distributed on an "AS IS" BASIS, # Unless required by applicable law or agreed to in writing, software # You may obtain a copy of the License at # you may not use this file except in compliance with the License. # Licensed under the Apache License, Version 2.0 (the "License") Table ROOMS has 4 columns but 3 values were supplied cur.execute("""CREATE TABLE ROOMS(ID INTEGER PRIMARY KEY AUTOINCREMENT, However, when my script goes to insert a value it gives me an error about only specifying 3 columns instead of 4 meaning its looking for me to specify the id column so im a little confused as to how to do auto-increment. From what I read online you just have to specific ID INTEGER PRIMARY KEY AUTOINCREMENT or whatever and then you insert and don't specify the id column. It works, but my next question is, how do I choose to update a specific record in the database? I would think it would be as simple as: c.I'm trying to use sqllite autoincrement feature with python. Newloc = raw_input("Change it to what (string)? ")Ĭ.execute('''UPDATE People SET location = :update_id''', Question = raw_input("Do you want to set location? (y/n) ") I corrected the indentation and adjusted the code: import sqlite3 Okay, so pasting might be a good Windows function, but for our example, it stunk. Your assistance would be greatly appreciated. In this example, I only have one record (row) in the table and all fields are set to TEXT except the ID field (INTEGER AUTOINCREMENT). I would then like to be able to prompt the user for a change and use the key field (ID) to update the SQLite record. In playing with the code, I was trying to read a record from SQLite and populate a set of variables to be displayed in Python. This assumes a SQLite database file test.db with a single table People that I would like to use to store some data, ID autoincrement field, NAME persons name, OCCUPATION, job, LOCATION where they are (home, work, etc). Sql = "UPDATE People SET location="home" WHERE id = "1"" Question = raw_input("Do you want to set location? ") Here is my sample Python code: import sqlite3 I am trying to understand using an SQLite database in Python and can grasp running queries, but would like to understand how to populate Python variables from SQLite fields.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |