I am basically dealing with GOLang and C code, i have created the below command and passing that
as an argument to C code with proper C to GO command, C.CString(sqlcmd). The C code does the concatenation of select frm table_name and other things required to form the complete query.
In the GOLang code i just need to create the required conditions for sql command.
But am facing an issue in this.
I have created a sql command using fmt.Sprintf as follows
sqlcmd = fmt.Sprintf("WHERE date=‘%s’ AND division=‘%s’ AND flag=‘%s’ AND block_no=‘%s’ AND case_no=‘%s’ frame_time||frame_division >= ‘%s’||‘%s’ ", date, division, flag, Block_no, Case_no, frame_time, frame_division)
When i print this command it gets printed as below
fmt.Printf(“sqlcmd:%s”)
sqlcmd: WHERE onair_date=20171002
AND service_division=‘SV01 ’ AND test_flag=’ ’ AND block_no=’ ’ AND case_no=‘00’
when i pass sqlcmd as argument and code gets executed i gives the below error
sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: Syntax error: End of unexpected file
sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: Syntax error: End of unexpected file
For debugging purpose,
i hard coded the same output command to sqlcmd and passed it as arguments and it works perfectly fine without any problem, even the DB query works perfectly and displays as per the created request.
sqlcmd = “WHERE onair_date=
20171002
AND service_division=‘SV01 ’ AND test_flag=’ ’ AND block_no=’ ’ AND case_no=‘00’”
But when ever i pass the sqlcmd directly as argument i get the above error.
I checked for spaces in the hard coded query and and the query generated from fmt.Sprintf i didn’t fine any.
Can anyone give any help or the correct method to frame the command.