Check isnull in the field of a row - codenameone

Is there any method for checking a field value of a row from an SQLite table that has a null value?
There are methods of the row like getInteger, getString,..... but no method for checking null value.

Related

nullable column with Postgres API

With libfq and the C API, is there a way to get the nullable metadata of a column from a query?
I'm just talking about the property of a column, not the NULL value from a resultset.
For instance, with MySQL:
mysql_fetch_field_direct()
does the job.
I tried with PQfmod, but without success.
Information about the table definition is not part of the result set data.
You can find out if the value is NULL, but not if the column is nullable or not.
A column in a result set need not be related to a certain column in a table!
To get information about a column's definition, query information_schema.columns. The is_nullable column will contain the information.

Create Null-able numeric column in Derived column component

I use SSIS in SQL Server 2016. I have to create a new column in my DataFlow. I use DrivedColumn component to create this new column. In this case I need a nullable numeric column like below image :
As you can see, I have error in this case.
How can I create null-able numeric in Derived column component?
In the derived column task there are NULL Functions that you can use if you would like to set a value to NULL.
Select the appropriate NULL function that corresponds to the datatype of your column and plug that into your equation.
You can use NULL(DT_CY) if your column is defined as currency.
Example. ([currencyAmount]>0? [currencyAmount]:NULL(DT_CY)
In the Derived Column task Null Functions can be found here:

Trying to insert in a table with primary key autoincrement but getting an error

INSERT INTO Locality(versionNo,localityName, localityType, constiCode, deleteFlag,
createdOn, lastUpdate,updatedBy)
SELECT 1, localityName, Localitytype, constituencyCode + '' + regionCode, 1,
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, CURRENT_USER
FROM dbo.MasterTable.
Msg 515, Level 16, State 2, Line 1
Cannot insert the value NULL into column 'localityCode', table 'GovMaster.dbo.Locality';
column does not allow nulls. INSERT fails.
I want to insert but the LocalityCode is primary key and should not be null. But I get that error above. The localityCode is primary key and it can not be null. And i want the localityCode to be auto generated, it should do an autoincrement on insert.
You're not inserting a value for localityCode, it's missing from your field list:
INSERT INTO Locality(versionNo,localityName, localityType, constiCode, deleteFlag,
createdOn, lastUpdate,updatedBy)
When you leave a field off the INSERT list, it gets a default NULL value. If it were an auto-incrementing ID field, it would be correct to exclude it, but it is not in your case. You either need to supply a value, or change the schema to allow NULL values for that field, or make it an auto-incrementing field.
Just cutting to the chase, the reason you are getting that error is because:
Problem:
You have a column name localityCode defined as a NOT NULL in your Locality table and it does not appear to be an auto-incrementing field.
Secondly, you are not passing any value in your insert statement below, hence it's passing a null value by default to your localityCode column.
Solution:
Ideally, you would want to pass some non-null values to your localityCode explicitly in your insert statement.
The other option would be change your null property for your localityCode column to accept NULL values.
Alternatively, if you want to set the localityCode column as an auto-increment field, you may want to look into this: Adding an identity to an existing column
Hope this helps!
Thank you guys.
I dropped the existing column and recreated it with localityCode INT IDENTITY(1,1) and alter the column to primary key after that.
:-)

tadoquery post: "cannot update non-nullable column with null" on identity column

I am trying to use a TAdoquery with MS SQL Server in a legacy delphi project.
The dataset contains a field that represents identity column in the SQL table. It has AutogenerateValue = arAutoInc and ProviderFlags [pfInWhere, pfInKey]. It also has Required = false.
After doing adoquery.Append I prefill fields and try to do adoquery.Post but get this error:
Non-nullable column cannot be updated to Null
All non-nullable fields are set to non-null before post, so the identity column is the only suspect. The TADOQuery has no joins (simple Select * from my_table), but it has look up fields and calculated fields, which may be null. For lookup fields and calculated fields I removed provider Flags to ensure those fields do not appear in the insert or update statement.
The identity field is NULL immediately before post, I see no insert command firing on the server in the Profiler, instead I just get this error.
Is it possible to preview the sql statement generated by the Tadoquery to insert a new row ?
I solved it, the issue was of course unrelated to the identity column.
The initial sql was select * from myTable, which meant that it also loaded a couple of extra columns that were not bound to any grid column in my DBGridEh.
After replacing * with an explicit list of the columns that I needed the INSERT worked.

When setting a column value to not null in sql server, do i have to set a default value for the column or should it work anyway?

If I use for example Entity Framework and try to make an insert, if the model to update has a string value or a bool, though not set, the models values cannot be null so they should handle the default value to be inserted in these fields?
If you're setting an existing column to NOT NULL and it was nullable before hand, then either
all existing rows already have a value for that column (or you update your table so that this condition is met)
or you have to provide a default value for the NOT NULL column so that any rows that contain a NULL will be filled with the default instead
You can do either of those two options - whichever works for you.
When setting a column value to not null in sql server, do i have to
set a default value for the column or should it work anyway?
When you are setting the constraint as NOT NULL that means you have to specify a value to that column. It cannot remain NULL. You can certainly specify any default value to that column.
If you dont want to give the value everytime to your column then it is better to set some default value to that column else you need to provide the value to that column whenever you will make an insert statement.
If you are setting column as NOT NULL with ALTER command then you have to be sure that all value of the column should not be null or you can set its default value. But In case of CREATE command,not compulsory to create default value since it will restrict for inserting null value with any DML command.

Resources