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;
Related
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");
I have a system which stores data from an online SQL Server database in local storage. Data records are uploaded and downloaded using a web service. I am using an ADO.Net Entity Data Model in my code.
On some upload requests for one table the routine fails when I try to call it giving an error message "The value 'null' cannot be parsed as the type 'Guid'." This only happens occasionally and I have not worked out how to repeat the problem. I have logged it 80 times in the last month and in that time the routine has been called successfully 1200 times.
I have five fields in the database record for this table that are defined as uniqueidentifiers. Two of these are 'NOT NULL' and the other three are 'NULL'. Here is the 'CREATE TABLE' query showing the guid fields in this table:
CREATE TABLE [dbo].[Circuit](
[CircuitID] [uniqueidentifier] NOT NULL,
[BoardID] [uniqueidentifier] NOT NULL,
[RCDID] [uniqueidentifier] NULL,
[CircuitMasterID] [uniqueidentifier] NULL,
[DeviceID] [uniqueidentifier] NULL,
CONSTRAINT [PK_CircuitGuid] PRIMARY KEY NONCLUSTERED
(
[CircuitID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
GO
ALTER TABLE [dbo].[Circuit] WITH CHECK ADD CONSTRAINT [FK_Circuit_RCD] FOREIGN KEY([RCDID])
REFERENCES [dbo].[RCD] ([RCDID])
GO
ALTER TABLE [dbo].[Circuit] CHECK CONSTRAINT [FK_Circuit_RCD]
GO
ALTER TABLE [dbo].[Circuit] WITH CHECK ADD CONSTRAINT [FK_CircuitGuid_Board] FOREIGN KEY([BoardID])
REFERENCES [dbo].[Board] ([BoardID])
GO
ALTER TABLE [dbo].[Circuit] CHECK CONSTRAINT [FK_CircuitGuid_Board]
GO
The data uploaded for the guid fields in this table looks like this:
{"__type":"Circuit:#WaspWA","BoardID":"edb5f774-5e5d-490c-860b-73c3419628cf","CircuitID":"e95bbfa3-2af6-49a5-94dd-c98924ec9a62","CircuitMasterID":null,"DeviceID":"daf12fce-675c-46d9-94c4-ed28c63cdf30","RCDID":null}
This record was created on one machine uploaded to the online SQL Server database and then downloaded to another machine.
I have other similar tables in the database which never give any problems. It is just this table which I am getting error messages from. The two fields which are defined as 'NOT NULL' (BoardID and CircuitID) always have data in them and are never null.
Is there something obvious that I have missed here?
The problem was that the value 'null', a string, was being written into my local copy of CircuitMasterID rather than null. So when I tried to write this to SQL it didn't like it. The SQL error message shows null in quotes but I was not sure whether this was because it was a string or because the error message put the value in quotes to delineate it.
The value 'null' had found its way into the CircuitMasterID field because I had written the value null out into some HTML and when this was saved back to the field it became 'null'. I am storing data in local storage and this does not give very good type control. Note to self 'must add better type control'.
I'm not sure that I'm getting an id primary key in my sqlite table.
When I create my table I use
CREATE TABLE IF NOT EXISTS HABITS (id unique, uid, text, orglvl, habitstatus)
The other properties are fine, and I can retrieve results.rows.item(i).text, but results.rows.item(i).id is NULL
Also upon Insert, when I try to get results.insertId, I get an error of "undefined", which started this whole wondering for me.
What am I doing wrong - how come I have no id's when I have created them in my table?
To get an autoincrementing column, you must use INTEGER PRIMARY KEY.
I set up a SQLite Database DB Connection via the CF Admin after installing the JDBC Driver. After setting it up I got a successful connection message. I also know that I connected successfully because if I run a simple select query it doesn't fail out and if I run a CFDump it shows the proper columns. To further test this simple select statement, if I changed the table name it does fail. So, it's not a connection issue.
I am simply trying to insert records into a table and then check to see if those records were added. These are the queries I am using:
<cfquery datasource="fooDB" name="foo">
INSERT INTO FooTable
(FooColumn)
VALUES
('Test')
</cfquery>
<cfquery datasource="fooDB" name="checkIfwasSuccessful">
SELECT *
FROM FooTable
</cfquery>
This is my SQlite table creator:
CREATE TABLE FooTable (
id INTEGER PRIMARY KEY,
FooColumn TEXT,
OtherColumn1 TEXT,
OtherCOlumn2 TEXT
);
The CFDump of the query checkIfwasSuccessful is an empty result.
Any ideas??
Thank you in advance!!
Use Cftransaction to verify that your query is being commmited.
Have you tried either a) supplying an id with the insert, or b) using the AUTOINCREMENT keyword after PRIMARY KEY?
I have a bunch of SQLite db files, and I need to merge them into one big db files.
How can I do that?
Added
Based on this, I guess those three commands should merge two db into one.
attach './abc2.db' as toMerge;
insert into test select * from toMerge.test
detach database toMerge
The problem is the db has PRIMARY KEY field, and I got this message - "Error: PRIMARY KEY must be unique".
This is the test table for the db.
CREATE TABLE test (id integer PRIMARY KEY AUTOINCREMENT,value text,goody text)
I'm just thinking off my head here... (and probably after everybody else has moved on, too).
Mapping the primary key to "NULL" should yield the wanted result (no good if you use it as foreign key somewhere else, since the key probably exists, but has different contents)
attach './abc2.db' as toMerge;
insert into test select NULL, value, goody from toMerge.test;
detach database toMerge;
actual test:
sqlite> insert into test select * from toMerge.test;
Error: PRIMARY KEY must be unique
sqlite> insert into test select NULL, value, goody from toMerge.test;
sqlite> detach database toMerge;
I'm not 100% sure, but it seems that I should read all the elements and insert the element (except the PRIMARY KEY) one by one into the new data base.