sqlite3

Insert row into table if it is empty and replace the existing row if it isn't in SQLite

I have a table in SQLite 3: CREATE TABLE foo ( bar TEXT ); It always has 0 or 1 rows. I want to write a query which updates the row if there is 1 row and adds the row if there are 0. What is the cleanest way to do it? ...

How to delete record from table?

Hi, I have a problem with deleting a record from sqlite3 database: conn = sqlite3.connect('databaza.db') c = conn.cursor() data3 = str(input('Please enter name: ')) mydata = c.execute('DELETE FROM Zoznam WHERE Name=?', (data3,)) conn.commit() c.close All is good, but delete doesn't work! Have anybody some idea? ...

what is wrong with this sqlite3 statement

Hi, I have written this sqlite statement and I am getting syntax error: update List SET number = (CASE WHEN number>=3 then number++ WHEN number=1 then 3 ELSE number END) WHERE listKey=3; I keep on getting : SQL error: near "WHEN": syntax error I tried various versions, adding braces at places and all, but can't figure out the erro...

Error inserting on Sqlite3 on Android

Hello. I have the following table on Sqlite3 on Android: Game ------ gameId That it was created with the following script: CREATE TABLE Game (gameId) INTEGER PRIMARY KEY AUTOINCREMENT);" When I'm going to insert data on table I don't put a value for column gameId. Doing this I get the following error: android.database.sqlite.SQLi...

How do I do an atomic INSERT IF NOT EXISTS equivalent in sqlite3?

The questions says it all really. I have a table and I want to insert a row if it doesn't already exist. or should I just do an insert and if the key constraint is violated then ignore it? ...

Insert Text with tilde in Sqlite3 on Android.

Hello. I'm trying to insert on Sqlite3 texts like 'descripción', and I'm geting on a shell conected to emulator with adb, strange caracters instead of 'ó'. I'm using the following data to insert: item.description = "Descripción del juego 1"; And I'm geting: Descripci|-n del juego 1 I've also tried this: item.description = new St...

Enable foreign keys on Sqlite3 version 3.5.9

Hello. I'm trying to enable foreign keys on a sqlite3 database doing this: sqlite> PRAGMA foreign_keys=ON; But it doen't work. How can I do it? Note: the database is on an Android device. Thanks. ...

add multiple columns to an sqlite database in python

Hi, I want to create a table with multiple columns, say about 100 columns, in an sqlite database. Is there a better solution than naming each column individually? I am trying the following: conn = sqlite3.connect('trialDB') cur = conn.cursor() listOfVars = ("added0",) for i in range(1,100): newVar = ("added" + str(i),) listOfV...

python sqlite question - Insert method

In the code below row is a tuple of 200 elements (numbers) and listOfVars is a tuple of 200 strings that are variable names in the testTable. tupleForm is a list of tuples, 200 elements in each tuple. The following code does not work. It returns a syntax error: for row in tupleForm: cmd = '''INSERT INTO testTable listOfVars values...

SQLite Crash on Inserting Items

I have three queries that I'm running through SQLite. These are what I'm running; the first is the table declaration and then the next 3 are the actual queries. Declaration: "CREATE TABLE IF NOT EXISTS items (busid INTEGER PRIMARY KEY, ipaddr TEXT, time TEXT DEFAULT (NOW()));" Queries: (Works) "INSERT INTO items (time, i...

Webservice n sqlite

I have web services and I want to save that data in SQLite in iPhone and also want to retrieve that data. Web services include 14 parameters, also includes image URL as well. Web service is SOAP in .NET. Please help me and provide me with the complete code how to do that. ...

Database query with relationships in Android

suppose I have the following tables sqlite> SELECT * FROM Artists; ArtistID|ArtistName 1 |Peter Gabriel 2 |Bruce Hornsby 3 |Lyle Lovett 4 |Beach Boys 5 |Supernatural sqlite> SELECT * FROM CDs; CDID|ArtistID|Title |Date 1 |1 |So |1984 2 |1 |Us |1...

Inserting SQL Data into Linked (Foreign Key) Tables in SQLite

I have two tables linked by a foreign key. Example: "CREATE TABLE one (id INTEGER PRIMARY KEY, data REAL, time TEXT NOT NULL DEFAULT (datetime('now')));" "CREATE TABLE two (id INTEGER PRIMARY KEY, parent INTEGER, CONSTRAINT fc_two FOREIGN KEY (parent) REFERENCES one(id));" So I'd like to do an INSERT INTO with an embedded JOI...

sqlite3 Database not opening after too many writes

This looks like a memory or caching problem, but I don't know how to really debug how it's happing. I'm using Objective-C in X-code for this program. This is how I'm opening the database: -(BOOL) open { if (sqlite3_open_v2([[documentDirectory stringByAppendingPathComponent:[surveyName stringByAppendingPathExtensions:@"sqlite"]] UT...

Easiest way to recast variables in SQLite

New to databasing, so please let me know if I'm going about this entirely wrong. I want to use databases to store large datasets (I use R to analyze data, which cannot load datasets larger than available RAM) and and I'm using SQLite-Manager in FireFox to import .csv files. 99% of the time I use reals, but would like to avoid all the ...

django - too many options when lanuching dbshell sqlite3

I have django 1.2.3.0 Final and I am using Python 2.7 In my setting, I have 'sqlite3' filled for the DATABASE_ENGINE. I am able to work with the sqlite3 (at the level of djano manage.py shell) until I am told that I need to access python manage.py dbshell At first I got the error "sqlite3 is not recognized...." Then I read thread...

sqlite subqueries with group_concat as columns in select statements

I have two tables, one contains a list of items which is called watch_list with some important attributes and the other is just a list of prices which is called price_history. What I would like to do is group together 10 of the lowest prices into a single column with a group_concat operation and then create a row with item attributes fro...

Sqlite3, Blob type in iphone

Hi everyone this is sabby. I am getting the data from a webservice and saving that data in sqlit3 database in iphone.I used the data type of video url as blob,but its not saving in database.But if i use the varchar then url is saved in database. Just help me for this ,as i am new to iphone development. Thanks everyone ...

Introducing a new table between parent and child tables

If I have a parent and a child table filled with data, is it trivial to add a new table between them? For example, before introduction the relationship is: Parent -> Child Then: Parent -> New Table -> Child In this case I'm referring to SQLite3 so a Child in this schema has a Foreign Key which matches the Primary Key of the Parent T...

ALTER COLUMN in sqlite

How do I alter column in sqlite? This is in Postgrsql ALTER TABLE books_book ALTER COLUMN publication_date DROP NOT NULL; I believe there is no ALTER COLUMN in sqlite at all, only ALTER TABLE is supported. Any idea? Thanks! ...