Saving comma delimited data from a web application - html

I am using ColdFusion 10, but this question can be true for any web-application. I am trying to save a set of checkboxes with the same name. When they are posted, the form variable stores them as a comma separated list of IDs. Normally I would receive it as a varchar parameter in a storedprocedure and will parse them in t-sql to get to the individual values and inserting them to a table. I have been using this technique for quite some time.
I just want to check with you guys if there is any newer way of doing this. Basically what I am asking is how do you save a bunch of html checkboxes into a database table elegantly without using some kind of grunt code, like parsing.

I might use listToArray( form.fieldname ) to turn the list into an array, then loop over the array to do inserts.

Probably this will work. First convert to xml and then use xml to insert into table:http://beyondrelational.com/modules/2/blogs/28/posts/10300/xquery-lab-19-how-to-parse-a-delimited-string.aspx

Related

transpose a table using talend

I would like to transpose a table like the one below:
into this:
I wanted to mention that the files are CSV files.
Thanks,
There is a solution to this, but it's inelegant and inefficient and may not work incase of a huge dataset (may run out of memory).
You can denormalise the whole input, by defining all the schema columns in the tDenormalize component, pass it across to a tMap to concatenate all the columns using a special character in between. The special character is just an identifier for the next component we are going to use.
Connect the tMaps output to a tNormalize and use the special character as the Item Seperator while the column to normalise should be the only column (which you concatenated to in the previous tMap) available.
This should do what you're looking for. If you wish to process the data after this instead of just transposing, you can use tExtractDelimitedFields component and use the "," as your field Seperator since its a csv.

MYSQL REGEXP with JSON array

I have an JSON string stored in the database and I need to SQL COUNT based on the WHERE condition that is in the JSON string. I need it to work on the MYSQL 5.5.
The only solution that I found and could work is to use the REGEXP function in the SQL query.
Here is my JSON string stored in the custom_data column:
{"language_display":["1","2","3"],"quantity":1500,"meta_display:":["1","2","3"]}
https://regex101.com/r/G8gfzj/1
I now need to create a SQL sentence:
SELECT COUNT(..) WHERE custom_data REGEXP '[HELP_HERE]'
The condition that I look for is that the language_display has to be either 1, 2 or 3... or whatever value I will define when I create the SQL sentence.
So far I came here with the REGEX expression, but it does not work:
(?:\"language_display\":\[(?:"1")\])
Where 1 is replaced with the value that I look for. I could in general look also for "1" (with quotes), but it will also be found in the meta_display array, that will have different values.
I am not good with REGEX! Any suggestions?
I used the following regex to get matches on your test string
\"language_display\":\[(:?\"[0-9]\"\,)*?\"3\"(:?\,\"[0-9]\")*?\]
https://regex101.com/ is a free online regex tester, it seems to work great. Start small and work big.
Sorry it doesn't work for you. It must be failing on the non greedy '*?' perhaps try without the '?'
Have a look at how to serialize this data, with an eye to serializing the language display fields.
How to store a list in a column of a database table
Even if you were to get your idea working it will be slow as fvck. Better off to process through each row once and generate something more easily searched via sql. Even a field containing the comma separated list would be better.

How to deal with user options and mysql database

I'm writing a PHP program. Each content has some options which stores users preferences. For example:
Where the content should be shown in the template?
In which categories or pages, the content should be loaded?
Now, I store these data in a single field named options as JSON. the final result is something like:
{
"locales":["en"],
"themes":{
"default":{
"width":"0",
"height":"0",
"top":"0",
"right":"0",
"bottom":"0",
"left":"0"
}
},
"pages":["aboutus\/"],
"categories":["all"],
"homepage":"false"
}
I have no problem to select data and filter rows using mysql regexp statement. But I have 3 other questions:
How to update a JSON field value in a single update statement?
Does it make sense to do such a trick at all (I mean using JSON)?
What other solutions do you recommend to store options, while there a lots of property to be stored?
AFAIK, there is no absolute way to do that in none-NoSQL database like MySQL. However, not exactly for JSON, you can see how FriendFeed uses MySQL to store schema-less data and it may give you some ideas.
UPDATE:
MySQL 5.7.8 and newer versions are now supporting JSON data type. There are some tutorials to help.

How can correctly save a csv with values list from neooffice / openoffice?

I need something like this:
Attivato;Nome;Categorie;Prezzo tasse escluse;Descrizione;Immagini
1;"Bracciale rock";11,12,13;130;"This is a long description.";http://s20.postimg.org/r08w8i4i5/perle.jpg,http://s20.postimg.org/tmjtbp6bx/bracciale.jpg
But if I open it with neooffice calc (or anyway in some spreadsheet program) it then export like this, at the best:
Attivato;Nome;Categorie;Prezzo tasse escluse;Descrizione;Immagini
1;"Bracciale rock";"11,12,13";130;"This is a long description.";"http://s20.postimg.org/r08w8i4i5/perle.jpg,http://s20.postimg.org/tmjtbp6bx/bracciale.jpg"
It won't retain things like 11,12,13 without converting them to strings
How can I fix this?
I tried really everything but no way... Tried any kind of import/export options, different programs, etc... I cannot do it.
I finally found a couple of ways.
(1) In neooffice/openoffice:
left empty the text separator field
check the 'detect special numbers' option
(2) As another alternative, I used google docs. That's good also to use for clients who usually use exel. Google docs/drive saves csv files in utf-8 encoding by default.
Also, for the problem of "string conversion" of multiple values like 5,7,9,6, I found that if you use semicolons (;) instead of commas, that works (I mean, it doesn't add "" when you save as csv AND doesn't read them as dates or other wrong data types). And in prestashop you can set the field and test separators accordingly.
Hope it helps other people.

mysql selecting multiple values wrapped in identical tags

I don't know if there is a better description of my problem, but here is what I need help with:
I have a field with lots of data, and the part I need to solve looks like this:
::field_x::<br />||field_x||519||/field_x||<br />||field_x||281||/field_x||<br />::/field_x::
I have to extract each number (id) from this, 519 and 281 in this example, and insert them in a field in another table, separated by spaces or commas. I know how to use SUBSTRING - LOCATE method, but that would return only the first instance, so is there a method to extract them all in one go?
SUBSTRING INDEX LOCATE will work. There is no built in functionality for regular expressions so unless you handle it before it gets to mysql...you're stuck using the SUBSTRING INDEX LOCATE method...
If you need to iterate through a dataset, you will need to initiate a cursor, or FOR loop and use a stored proc.
parse results in MySQL via REGEX