i used mysql as my RDBMS and recently i have heard that you should not insert null in your DB,
i mean instead of having a lot of fields that they may or may not have value create a field and insert a data type like JSON in it.
e.g. i have table named as message
it contains fields like MessageType(it can be a map a video a photo or text,...) and it also has fields like(latitude,longitude for map),(photoid,photoPath,photoHash,... for photo),(videourl,videoHash,videoId,...) and so on. So when a message is type of text for example,it's field has value but i pass null in other fields like latitue,videourl,...
Is it a correct approach?Can you help me with better approach?
Regards
Instead of NULL try a different value like -1 or 0 or NA or a simple -
Related
I have a database where there are 3 tables with 3 columns which are AES_ENCRYPTed.
One table has a column which is a VARCHAR(255) with charset latin1. It contains some text encrypted.
Applying the AES_DECRYPT with an UNHEX of the column value shows the output of the real value properly.
Another table has a column which is a mediumblob with charset utf8. It contains some large text encrypted.
Applying just the AES_DECRYPT and then casting it to char displays the original value properly too.
But the 3rd table has a column which is also a mediumblob but charset latin1. It contains a large JSON data stringified.
Now when I apply just the AES_DECRYPT('<column_name>', '') it outputs null. Applying unhex or casting the column to other types before the decryption did not do anything.
For the first 2 tables, just applying the AES_DECRYPT without the conversion also output something.
But the 3rd table does not output anything; just shows NULL.
Any idea what is happening here? It would be very helpful if someone with DB expertise can point me to the right direction why the output is NULL and what needs to be done in the query to get the real output.
EDIT:
The DB Columns are populated by a microservice which uses JAVA Hibernate ColumnTransformer for doing the write and read.
write = AES_ENCRYPT(, ), read = AES_DECRYPT(, )
The values posted via this is also returned properly in the GET response. But the same query does not output the 3rd column value and print NULL as described.
With this structure :
And this command :
UPDATE encryption SET `encrypted` = AES_encrypt(CONVERT(`json` USING latin1), "key");
UPDATE encryption SET `decrypted` = AES_decrypt(encrypted, "key");
This works well for me.
However blobs doesn't any character sets...
Hi Everyone of StackOverflow Community,
I have a doubt in an activity that I have to do for homework.
I want to know how I can increment one field in every document that is filtered by a specific condition. My problem is not in the update code, in termes that this number field to increment was a number type (int, float, double,...), but yes when I have to increment that field values (numbers) in a field that has String as a field type.
It give my that error (ScreenShot):
ERROR MongoDB Update
Thanks.
See you,
One way to solve it is like JohnnyHK said in the comment:
You can't do that in a single update; you'd have to find the document, convert the string to number, add 5, convert it back to a string, and update the document with $set.
Another possibility is found in the following question:
how to convert string to numerical values in mongodb
How do I capitalize all text in a column of data in an Access Query while keeping the name of the field the same?
I tried entering "SPEC: StrConv([SPEC],3), but I get an error that I have a circular argument (which, isn't too surprising). So how do I get around this?
Is there a totally different approach to capitalizing in queries?
Given: we have a field named [SPEC].
Problem: need query to grab [SPEC] and convert it to all caps, but
with the same field name
Added: We will call the table that holds the field [SPEC],
[tblTable]
Solution:
What we need to put in the query builder is the following:
SPEC: UCase([tblTable].[SPEC])
That way the machine can figure out that Query.SPEC isn't the same identifier as tblTable.SPEC
Equivalently:
SELECT UCase([tblNames].[FirstName]) AS FirstName
FROM tblNames;
How about using the Ucase function
Ucase(String)
I am trying to insert or edit the bit value to "0" or "1", but either returns me a blank.
Could someone tells me how to insert the value in it?
Also, Is that possible to not use bit type but Boolean? I see there's a Boolean type in the list of types
Thanks
Hi, I have uploaded the picture, the cell in the table is blank, but I have tried several times, add, update, all take effect, but cell keeps blank...
Generally speaking, for boolean or bit data types, you would use 0 or 1 like so:
UPDATE tbl SET bitCol = 1 WHERE bitCol = 0
See also:
Which MySQL data type to use for storing boolean values
How do you create a yes/no boolean field in SQL server?
If you're using SQL Server, you can set the value of bit fields with 0 and 1
or
'true' and 'false' (yes, using strings)
...your_bit_field='false'... => equivalent to 0
Your issue is in PHPMyAdmin itself. Some versions do not display the value of bit columns, even though you did set it correctly.
I want to check in mysql if a column is either blank, ie '', or 0.
Is there a way to do this with one condition?
Like
WHERE order_id > ''
or
WHERE order_id != ''
Would either of these work, or is there a different solution?
This is more a question of data quality. In a well designed database, there should be a fairly clear-cut difference between '' and 0.
If you're being vague about it, there are quite a lot of values that could be interpreted as "blank" in addition to these two. NULL is the obvious one, but what about white space? Or a string containing 0.00, or even if you're looking for a numeric value, any non-numeric string.
Ideally, the data should be stored in a format that matches the type of data it is supposed to hold - for example, if you're expecting a numeric field, it should be an int, or another numeric type, depending on exactly what you want to store. That way, it can never contain a string value, so you would never need to check for it.
If you can't change the type in the DB itself, the next best solution is to cast the value as that data type you are expecting in the select query. eg:
SELECT CAST(myfield as int) as myfieldnum FROM table where myfieldnum != 0
See the MySQL manual for more info: http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html
However, in the end, it does depend on exactly what you are expecting the data field to contain, and how you want to react to different types of content.
Does this qualify as one condition?
... WHERE order_id IN ('0', '');
I experimented a bit and it seems the answer is:
WHERE order_id != 0
This will show results where order_id is not 0 and also not blank
why dont u use a smiple query where both of ur conditions are going to be tested
select * from tbl_name where order_id=' ' or order_id = 0
try this it will work