How do I fix not null constraints error on flutter? - sqlite

I have an db which has two table: note and category. There is a schema below for my tables. I want to insert a record to the note table but I'm getting this error below. Can anyone please help?
Here is the method I create for insert a record to note table and the error which I'm getting from this process.

It clearly states that you declared your category_id as NOT NULL but you are passing a null value while trying to insert a note.
There may be 2 approach here,
You can simply remove NOT NULL constraint from your table definition by modifiying "category_id" INTEGER NOT NULL DEFAULT 1 to "category_id" INTEGER DEFAULT 1
You should really be sure that you are passing a non-null value to category_id in insert operation
As I see from your logs, it clearly says that one of the argument you are passing is null and it causes this crash.
Hope these helps you to detect your problem and fix it.

Related

Python with Sqlite3 Syntqx error doing a select query with where condition where parameter is a variable of type integer [duplicate]

I'm trying out statements for creating a database, and after 10 entities without any issues I ran into this error
Error: Near line 83: near "Transaction": syntax error
The first line is line 83 with it's context of creating a table
CREATE TABLE Transaction (
TransactionID INTEGER,
AccountID INTEGER REFERENCES User (AccountID),
ItemID INTEGER REFERENCES Item (ItemID),
Method STRING,
Price INTEGER,
TransactionDate DATE,
PRIMARY KEY (TransactionID)
);
Now I can't seem to find the issue, and suggestion's of something with ASCII using the wrong space couldn't be solved by writing the same thing again manually.
I haven't even gotten around to checking the integrity of my foreign keys, and it's not working. Hopefully somebody could provide some insight on what I'm missing.
Transaction is one of the reserved names in SQLite. For a full list see here.
Ways to solve this issue are:
Change the Table name to a word that isn't reserved.
or
Quote the reserved name by using one of these 4 listed quote marks
'keyword'
"keyword"
[keyword]
`keyword`

Check if set of variables contains NULL in Oracle Apex PL/SQL

What is the most efficient/cleanest way to check if a set of variables in Oracle Apex includes a null value?
The obvious answer would be:
-- this is a PL/SQL Function in a Oracle Apex validation
v_item1 := :P1_ITEM1;
v_item2 := :P1_ITEM2;
(..)
if v_item1 is not null and v_item2 is not null ...
But is there a cleaner way that I'm not aware of?
I think the way you have it in your question is the best and most obvious way to do it, i.e.
if v_item1 is not null
and v_item2 is not null
...
However, there is another option:
if least (v_item1, v_item2, ...) is not null then
This works because least always returns null when any of its arguments is null.
Conversely, if you want to check several items are all null:
if v_item1 is null
and v_item2 is null
...
then you could use this:
if v_item1||v_item2||... is null then

Views,Entity,Cannot deduce a primary key

I made a view so the back hand of my website is more coherent. Then i tried to map it to my entity schema.
I had the message :
No primary key defined, could not deduce a primary key, table excluded
So i made one ! I made sure it was something unique by combining 3 columns that cannot be identical when combined. And i called that new column "id".
Entity dosen't seems to agree with the unique aspect of my "id" because the error message wont go away and i can't import my view...
Well, i had to use the sql function ISNULL(id,) on my "id" clolumn, making it a not null value so Entity understand that it could NEVER be null and therefore, detecting it as a potential primary key

Dynamic Data Cannot insert the value NULL

I 'm working on an ASP.NET Dynamic Data Entities Web Application.
When trying to insert a new entry in one of the tables, with some value in the column_name field, I get the following message :
Cannot insert the value NULL into column 'column_name', table 'DATABASE.dbo.table_name'; column does not allow nulls. INSERT fails.
The column properties are :
Entity Key : True
Nullable : False
Type : String
I believe Dynamic Data is trying to send null value to entity framework for some reason, but I don't know which.
Do you know why Dynamic Data is behaving that way ?
Or have you any idea how to debug the insert process ?
Thanks
I found where the problem come from. A table from the database the model is based contains a trigger. For some reason the model makes an association between the two tables involved in the trigger.

trigger for updating a value

I am a newbie in PLSQL and I would like to create a trigger that checks first if there is a record in a table before making an update.
The code I got so far is:
CREATE OR REPLACE TRIGGER table_bu
BEFORE UPDATE ON employee
FOR EACH ROW
DECLARE
v_employee_id:=employee.employee_ID%TYPE;
BEGIN
SELECT employee_id INTO v_employee_id FROM employee;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR (-20001,'data not found');
END;
How I can create a trigger that checks up if a record exists in the table and if it does not exists does not allow the update.
My table estructure is:
employee_id NUMBER
employee_name VARCHAR(20)
employee_salary NUMBER
...
Thanks
You are on a wrong way. The trigger as it is will throw runtime 'Mutating table' error even after fixing syntax error - you missed semicolon after raise_application_error(also it should take 2 arguments, not one). Correct syntax :
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR (-20001, 'data not found'); -- 1st parameter -error code
Update
As far as I understand the updated version of the question, you want to show error if record doesn't exist. The problem with row level trigger approach is that it won't be executed if nothing is found due to condition in WHERE. The simplest way is to check number of rows affected on client side and raise an error there. Or you can write a procedure that checks sql%rowcount after executing desired update, and then throw an exception if it's 0.
If you prefer to do in a hard way, you can create package variable which of type employee.employee_ID%TYPE, before update statement level trigger that resets variable (say set it to null), after update row level trigger that sets this variable to NEW.employee_ID, and after update statement level trigger that throws an exception if the variable is null. Note: this will properly work for individual updates only.
"How I can create a trigger that checks up if a record exists in the table and if it does not exists does not allow the update."
There is really only one practical way to do this - use a referential constraint (foreign key).

Resources