How update DB Value with NULL using Grails - grails

I am trying to update the DB value to NULL using Properties, but the NULL values are not updated.
The following is the code snippet
def a = Docs.findById(1)
a.properties = b
b has the following values
[name:abc, level:null]
Data appears not to be saving into the DB. How can I save the data?

Related

How to handle an autoincremented ID in HANA from a SAPUI5-application?

in my SAPUI5-Application I got the following function that takes the data and creates an entry in my HANA DB:
onCreateNewCustomer: function(){
var oEntry = {};
oEntry.NAME = this.byId("name").getValue();
oEntry.CITY = this.byId("city").getValue();
oEntry.PHONE = this.byId("phone").getValue();
oEntry.ID = this.byId("id").getValue();
// Post data to the server
this.getOwnerComponent().getModel("CustomerModel").create("/Customer", oEntry, null);
this.byId("createCustomer").close();
//location.reload();
}
The creating process works and my entries get saved. In the next step I wanted to implement my table in HANA in that way, that the ID of the entries will be autoincremented so the user does not have to enter it. I used the following command to create my table:
create column table TABLE
(ID bigint not null primary key generated by default as IDENTITY,
FIRSTNAME nvarchar(30))
That worked, table is created. The problem now is, if I use the code above without providing the ID, the following error is logged by the console:
The following problem occurred: HTTP request failed 400,Bad Request,The serialized resource has an missing value for member 'ID'.
The entry does not get saved in my DB. If I execute the following SQL-Statements in my HANA Workbench without providing the ID, it works:
insert into TABLE (FIRSTNAME) values (‘David’);
insert into TABLE (FIRSTNAME) values (‘Mike’);
insert into TABLE (FIRSTNAME) values (‘Bobby’);
So I did some searching on google but did not find a proper solution on how to do this. My goal is that the entry gets saved and the ID is provided by my HANA DB without providing it from my SAPUI5 Application.
Probably you are using ODataV2 XSODATA implementation which does not support auto-increment. The possible solution here is to use a database sequence and then with a separate request get a value from it and use it in OData create statement.
Did you try creating a new record by commenting out the below code like ?
oEntry.ID = this.byId("id").getValue();
With identity fields, if you provide the value you have to explicitly identify that you are providing the column value. Otherwise, just omit the columnn name and value from the INSERT command.

Overriding data of local copy of database object, Rails

I want to be able to override the instance of a database object without affecting the original
Object #users = User.all with a table attribute :status
#users[0].status = nil
Causes the status attribute to equal to nil when I read it with #users[0].status
However, when I do:
#users.find(1).status = nil
Does not change the status, notably a sql query is called when I use the find command, as such it is the database data that I am receiving
I tried using the .dup and .clone methods
#users=User.all.dup
Did not work
How do I go about with this? Do I have to create a temporary table? I am using postgres

Grails getPeristentValue returning null for clearly existing values

I'm running into a situation where a record is returning null for getPersistentValue(name) even when I can verify that the value was NOT null.
Test:
//get it
def team =Team.get(params.id)
if(team){
log.debug(team.dateCreated);//logs date correctly
team.properties=params;
log.debug(team.getPersistentValue('dateCreated');//logs NULL???
}
It does not do this for all records. The only obvious difference I can find is the "version" column kept by grails, but manually messing with this didn't alter the behavior. What situations would cause this method to return null when the record exists and the value was set on it?

How to save NULL in SQL DB using c#

I need to save just NULL in a column of SQL DB Table. but it is saving as 'NULL' or "" (blank). How to save just NULL?
There is a special object: DBNULL. You can handle this as null.

Exception in System.Data.Entity.dll but was not handled in user code

I need to count the number of the rows in my database with the entity framework. I am using the LINQ method "Count".
Here is the code:
QvDb dba = new QvDb();
if (dba.KUser.Count(us => us.FacebookId == values["FacebookId"]) == 0)
As you can see the values["FacebookId"] it's a post array variable, and the dba object variable it's the database model builder.
When I am trying to access to the page i got this exception:
An exception of type 'System.NotSupportedException' occurred in
System.Data.Entity.dll but was not handled in user code
Additional information: LINQ to Entities does not recognize the method
'System.String get_Item(System.String)' method, and this method cannot
be translated into a store expression.
For the record, the array is not null. It is a string that posted from the form.
When using LINQ to entities, all parts of your LINQ statement must be supported by the database.
values["FacebookId"] is a local dictionary. So it cannot be executed on the remote SQL database.
Pull the value from the dictionary first into a local variable, then execute your LINQ statement.
QvDb dba = new QvDb();
var id = values["FacebookId"];
if (dba.KUser.Count(us => us.FacebookId == id) == 0)

Resources