I am writing a simple program in python that links to an SQL database for storing data, I have been testing all the queries that I want to run in the Sqlite3 shell before taking them across to python so that I know they work.
INSERT INTO Account (emailAddress, password) VALUES ('n.winspear1#gmail.com', 'testing');
I can't seem to get this one working it keeps throwing...
Error: near "#gmail": syntax error
I'm not sure what's wrong with the syntax, I'm assuming it's something quite simple, I am somewhat new to SQL so I don't know all the syntax.
Table Creation:
CREATE TABLE Account (
accountID INTEGER PRIMARY KEY AUTOINCREMENT,
emailAddress TEXT NOT NULL,
password TEXT NOT NULL);
Any help is appreciated.
Thanks :)
INSERT INTO Account (emailAddress, password) VALUES ("n.winspear1#gmail.com", "testing");
Related
I am trying to insert clients on a table(importing them from a csv), the email column needs to be unique(in the csv the a client can appear more than one time, the last instance has the correct info) and the ids are created with an autoincrementing value (this is why i cant use select or replace), im trying to use the syntax found in the sqlite guide(and in every question about ON CONFLICT DO UPDATE found here) but sqlite throws a
SQL logic error near "ON" :syntax error
the query goes like this(using VB)
sqlQuery = "INSERT INTO clients(name1,name2,address1,address2,plz,city,country,phoneNumber1,phoneNumber2,cellPhoneNumber,fax,email) VALUES (?,?,?,?,?,?,?,?,?,?,?,?) ON CONFLICT(email) DO UPDATE SET name1=excluded.name1,name2=excluded.name2,address1=excluded.address1,address2=excluded.address2,plz=excluded.plz,city=excluded.city,country=excluded.country,phoneNumber1=excluded.phoneNumber1,phoneNumber2=excluded.phoneNumber2,cellPhoneNumber=excluded.cellPhoneNumber,fax=excluded.fax,email=excluded.email;
Hi everyone I am having some problems with my SQLite database in my java program. I am trying to retrieve data from a couple of tables but it says my table doesn't exist. I have checked using DB Browser and it's definitely there, so I'm not sure what I'm doing wrong. This is the error I receive:
[SQLITE_ERROR] SQL error or missing database (no such table: staff_clocked_in.clock_in_time)
SELECT * FROM staff, staff_clocked_in.clock_in_time WHERE staff.staff_id = staff_clocked_in.staff_id;
I'm sure my tables exist and there is data in both tables, here is a screenshot of my db browser.
If it helps, this is how I have setup my tables:
STAFF:
CREATE TABLE IF NOT EXISTS staff (staff_id INTEGER PRIMARY KEY NOT NULL, first_name TEXT NOT NULL, last_name TEXT NOT NULL, job_title TEXT NOT NULL);
STAFF_CLOCKED_IN:
CREATE TABLE IF NOT EXISTS staff_clocked_in (staff_id INTEGER PRIMARY KEY NOT NULL REFERENCES staff(staff_id), clock_in_time DATETIME NOT NULL);
Can anyone see anything wrong with my query? I'm not good with databases so hopefully it's just something simple.
The error message is correct staff_clocked_in.clock_in_time is not a table.
You should use staff_clocked_in instead which is your table.
So the fixed query should look like
SELECT *
FROM staff, staff_clocked_in
WHERE staff.staff_id = staff_clocked_in.staff_id;
I am creating a table in SQLite Database which will only store a single data, else if data exists in the table, it should be deleted before inserting a new data.
This is the syntax i used to create the table
CREATE TABLE my_login_info (
id BOOLEAN PRIMARY KEY
DEFAULT True
CONSTRAINT one_row_only CHECK (id)
NOT NULL,
username STRING,
password STRING
);
however when i am trying to insert the data to the table while the table is empty, it gave an error.
Error while committing new row: CHECK constraint failed: one_row_only
Any idea what is the caused the problem?
You can use INSERT OR REPLACE to insert a new record or update the existing one that matches the key field, eg:
INSERT OR REPLACE INTO my_login_info (id,username,hash)
VALUES (true,someuser,somehash)
Just make sure you don't store the password as cleartext. Only store a strong hash. If you don't need the hash for authentication, you could get away with storing a short hash, ie only part of the full hash.
That's what git does for example, when it displays a short hash for each file version instead of the full hash
i'm using the SQLite function from phonegap(1.2) on my app, and after quitting the application and restarting it, all data that i previously stored to the database is gone. how can i prevent loosing the data and where is the application stored on the device(Android, iPhone).
Create Table:
function favouritesInit(transaction){
transaction.executeSql('CREATE TABLE IF NOT EXISTS FAVOURITES (id INTEGER PRIMARY KEY, lat, ln, title, cont)');
}
Insert:
var statement = 'INSERT INTO FAVOURITES (lat, ln, title, cont) values('+the_fav.getPosition().lat()+', '+the_fav.getPosition().lng()+', '+the_fav.getTitle()+', '+content+')';
transaction.executeSql(statement);
thanks
You should make sure the problem is that the database is dropped once you close your application. It seems to me that it is just that the data is not getting into the database with your insert. With that code you passed, I can only guess, but if I were you I would run a transaction to read the data from the database right after inserting it just to make sure it actually makes its way to the database.
The problem is that your not passing a value for the primary key.
Your table has an id as primary key, and because of that it can't be null. The only exception is when you declare the id as 'AUTOINCREMENT': in that case, if you don't pass a primary key value, the database will assign the next available value from a sequence table created for that purpose.
Hope this helps: https://www.sqlite.org/autoinc.html
Cheers!
OK, this is probably pretty basic stuff, but it took me quite some time to figure it out. And I guess there are a lot more .NET programmers like me, new to Monotouch and SQLite who don't know this.
I use Ado.NET (System.Data) with Monotouch and SQLite. In SQLite, every row of every table has an 64-bit signed integer called ROWID. You can use this, or if you prefer you can specify a field with INTEGER PRIMARY KEY AUTOINCREMENT, which SQLite will link to ROWID.
But how do you retrieve the value of this field after inserting a new record? Something like the ##identity keyword in Sql Server?
Searching around I found that the c-library for iOS of SQLite has a method sqlite3_last_insert_rowid() to retrieve this, but there is no equivalent of that in Mono.Data.Sqlite. In an older implementation (Mono.Data.SqliteClient) there was a LastInsertRowID() method, but that method disappeared in Mono.Data.Sqlite. Why?
SQLite has some internal core functions. One of these functions is last_insert_rowid(). So all you have to do is to issue a command "SELECT last_insert_rowid()". Example in Monotouch:
public long GetLastInsertRowId(SqliteConnection connection)
{
// Assuming connection is an open connection from your INSERT
using (SqliteCommand command = new SqliteCommand("SELECT last_insert_rowid()", connection))
{
return (long)command.ExecuteScalar();
}
}
Or you can combine the select with your insert, example:
string SqlCommand = "INSERT into Customers ([Name], .... [City]) VALUES (#Name, ... #City);SELECT last_insert_rowid();";