It was a typo in my original question. Below is what i have observed.
My query looks like this -
String query = select * from table1 where guid is not missing and doc_type='xyz' and (guid in $guid_list);
I have my guid_list as below -
List listOfGuid = new ArrayList<>();
listOfGuid.add("a1b3594f-0b76-4c54-8206-db2c16286320");
com.couchbase.client.java.document.json.JsonObject placeHolders = com.couchbase.client.java.document.json.JsonObject.create()
.put("guid_list", JsonArray.from(listOfGuid));
N1qlQuery statement = N1qlQuery.parameterized(query,placeHolders);
This doesnt work. But if i try to pass the guid_list with single quote and hardcode the list in my query it works fine. Not sure why it doesnt work when i pass it as list. Is it because when i pass as list it goes in as double quotes ["a1b3594f-0b76-4c54-8206-db2c16286320"] instead of ['a1b3594f-0b76-4c54-8206-db2c16286320'].
The statement may not formed properly. Looks like there is missing quotes.
The following is curl command.
curl -v http://localhost:8093/query/service -H "Content-Type: application/json" -d '{"statement":"select * from table1 where doc_type=\"xyz\" AND guid in $guid_list;","$guid_list":["123","234"]}'
Related
I'm using a shell script to launch SQL query, works fine.
I would like to replace, inside MySQL database, a specific code, which is different depending of the website.
See image below :
My query is the following :
mysql -D DATABASE_NAME -e "UPDATE TABLE SET params = REPLACE(params, '%OLD_CODE%', 'NEW_CODE') WHERE element = 'EXTENSION'"
The problem is : the% OLD_CODE% zone does not work. I have to enter the exact string.
Below the content of PARAMS field from MySQL database :
{"com_difficulty":"3","clubcode":"OLD_CODE","shownews":"1","com_calViewName":"flat","darktemplate":"0"}
I need to replace OLD_CODE by a NEW_CODE, without loosing settings inside PARAMS field.
Problem, since OLD_CODE string is different for each site, how to replace each OLD_CODE string ?
I have laso tried with * caracter to take everything but does not work.
Example:
how to replace this
{"com_difficulty":"3","clubcode":"546465-595gfd-gfgfds65-5654gfd","shownews":"1","com_calViewName":"flat","darktemplate":"0"}
by this :
{"com_difficulty":"3","clubcode":"fg5gfdgfq-grefdg-gredfgfd","shownews":"1","com_calViewName":"flat","darktemplate":"0"}
Thanks
L.
this query works :
mysql -D DATABASE_NAME -e "UPDATE TABLE SET params = REGEXP_REPLACE(params, '\"clubcode\":\".+?\"', '\"clubcode\":\"TOTO\"') WHERE element = 'EXTENSION'"
im trying to detect and delete a line break out of a subject (called m.subject) mail information retrieved via CONCAT out of a mysql database.
That said, the linebreak may or may not occur in the subject and therefore must be detected.
My query looks like this:
mysql --default-character-set=utf8 -h $DB_HOST -D $TARGET -u $DB_USER -p$DB_PW -N -r -e "SELECT CONCAT(m.one,';',m.two,';',m.three,';',m.subject,';',m.four';',m.five,';',(SELECT CONCAT(special_one) FROM special_$SQL_TABLE WHERE msg_id = m.six ORDER BY time DESC LIMIT 1)) FROM mails_$SQL_TABLE m WHERE m.rtime BETWEEN $START AND $END AND m.seven = 1 AND m.eight IN (2);"
I tried to delete it afterwards, but getting in performance trouble due to several while operations on all lines already. Is there an easy way to detect and cut it directly via the CONCAT buildup? It is crucial to retrieve only one line after extraction for me.
Updating/changing the database is not an option for me, as I only want to read the current state.
All of the other variables that make this work are tested and working correctly so I'm obviously doing this wrong.
I have a bash script that first selects some mysql data and stores into a new variable.
Then it goes on to connect again and update the database.
title=$(mysql -u $user -p$pass -h $host dbname | SELECT post_title FROM wp_posts WHERE ID=$8);
mysql --host=$host --user=$user --password=$pass dbname <<EOF
UPDATE wp_my_music_lib SET title = "$title" WHERE track_id=${4}${6};
EOF
The title entry is always blank which says to me that the initial SELECT isn't working properly. It should also be noted that the data expected from the select result has white space and special chars in it ie :
Some Artist (10/10/13)
I thought quoting the var "$title" would fix any potential problems with gobbling but that isn't the issue here as I've tried selecting a single numerical object from a different column and that doesn't work either.
If I hard code the title var it works as expected.
1) Can you see what I'm doing wrong?
2) Is it possible to perform all of the above with one db connection instead as that would make more sense?
mysql | SELECT pipes the output of mysql to a command called SELECT, which is сertainly not what you want.
To execute a query via mysql and capture the output you can use this syntax:
title=$(mysql -B dbname <<< "SELECT post_title FROM wp_posts WHERE ID=$8")
You could also execute the SELECT in a subquery to avoid multiple calls to mysql:
mysql --host=$host --user=$user --password=$pass dbname <<EOF
UPDATE wp_my_music_lib SET title = (
SELECT post_title FROM wp_posts WHERE ID=$8)
WHERE track_id=${4}${6}
EOF
I am storing output of MySQL query in a varible using shell scripting. The output of SQL query is in multiple rows. When I checked the count of the variable (which I think is an array), it is giving 1. My code snippet is as follows:
sessionLogin=`mysql -ugtsdbadmin -pgtsdbadmin -h$MYSQL_HOST -P$MYSQLPORT CMDB -e " select distinct SessionID div 100000 as 'MemberID' from SessionLogin where ClientIPAddr like '10.104%' and LoginTimestamp > 1426291200000000000 order by 1;"`
echo "${#sessionLogin[#]}"
How can I store the MySQL query output in an array in shell scripting?
You can loop over the output from mysql and append to an existing array. For example, in Bash 3.1+, a while loop with process substitution is one way to do it (please replace the mysql parameters with your actual command)
output=()
while read -r output_line; do
output+=("$output_line")
done < <(mysql -u user -ppass -hhost DB -e "query")
echo "There are ${#output[#]} lines returned"
Also take a look at the always excellent BashFaq
I have a name stored in the variable username and would like to pull users row information when I try
result = dbh.query("SELECT * FROM maintab WHERE user = '#{username}'")
I get no results. If I put in the username by hand however, it does return a result. How format my query so that I may use variables?
Try to debug this way:
username = "Peter" # any of your real name
result = dbh.query("SELECT * FROM maintab WHERE user = '#{username}'")
it should work. Looks like your username is nil or blank
Open up IRB and try to print what you have.
How does #{} behave with single quotes vs escaped double quotes?
That should answer your question.