Codeigniter concat_ws not working - codeigniter

Getting error when I tried like this:
$ci =& get_instance();
$ci->db->select("CONCAT_WS(' ',users.name_first,users.name_last) AS user_name,CONCAT_WS(' ',advertisers.name_first,advertisers.name_last) AS advertiser_name,image,advertiser_reviews.last_updated");
$ci->db->join('users', 'users.id = advertiser_reviews.user_id');
$ci->db->join('advertisers', 'advertisers.id = advertiser_reviews.advertiser_id');
$ci->db->order_by('advertiser_reviews.id','desc');
$ci->db->limit(1);
$query = $ci->db->get('advertiser_reviews');
Error as follows:
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM (`hc_advertiser_reviews`) JOIN `hc_users` ON `hc_users`.`id` = `hc_advertis' at line 2
SELECT CONCAT_WS(' ', `hc_users`.`name_first`, `hc_users`.`name_last)` AS user_name,
CONCAT_WS(' ', `hc_advertisers`.`name_first`, `hc_advertisers`.`name_last)` AS advertiser_name,
`image`,
`hc_advertiser_reviews`.`last_updated`
FROM (`hc_advertiser_reviews`)
JOIN `hc_users` ON `hc_users`.`id` = `hc_advertiser_reviews`.`user_id`
JOIN `hc_advertisers` ON `hc_advertisers`.`id` = `hc_advertiser_reviews`.`advertiser_id`
ORDER BY `hc_advertiser_reviews`.`id` desc LIMIT 1

try to use $this->db->query("your sql query")
EDIT:
try to avoid the auto-quoting feature of the CodeIgniter DB class with
$this->db->select("your-query",FALSE)

There is sign ` at the Codeigniter generated code at the end
SELECT CONCAT_WS(' ', `hc_users`.`name_first`, `hc_users`.`name_last)`

$this->db->select('what of sql uncion' ,false);
the false tell ci to ignor escaping with `

Just came across this post where I had the same issue and you can get around the issue by a clever use of spaces.
$ci->db->select("CONCAT_WS(' ',users.name_first,users.name_last ) AS user_name )
As opposed to
$ci->db->select("CONCAT_WS(' ',users.name_first,users.name_last) AS user_name )
If you insert a space before the last closing bracket of the CONCAT_WS function then the CodeIgniter auto-quoting feature won't get confused about where the `s need to go. It also means you dont have to use the db->query() function.

Related

Oracle Query in Codeigniter giving ORA-01722 and ORA-01756

Im usually use mysql database in my website, but i trying to learn more about the oracle...
My code working 2days ago, but right now its giving an error message such as ORA-number
this is my database fields
KODE_GUDANG CHAR
GUDANG CHAR
LASTUPDATE CHAR
KODE_UNIT CHAR
NOMER_REKJURNAL CHAR
KODE_GUDANG_KREDIT CHAR
this is my models for query
function getDataOneColumn($getCol, $table, $column, $id) {
return $this->db->query("SELECT $getCol as val FROM $table WHERE $column = $id")->row_array();
}
This is for my controller that giving an error : ORA-01722
$this->data['no_rek'] = ($this->data['no_rek'] =='')?$this->m_dao->getDataOneColumn("NOMER_REKJURNAL","TBL_MASTER_GUDANG","KODE_GUDANG",$this->data['kode_gdg'])['VAL']:$this->data['no_rek'];
and after that i reading the docummentation, its means "You executed a SQL statement that tried to convert a string to a number"
i try to change my code to
$this->data['no_rek'] = ($this->data['no_rek'] =='')?$this->m_dao->getDataOneColumn("NOMER_REKJURNAL","TBL_MASTER_GUDANG","KODE_GUDANG",'"'.$this->data['kode_gdg'])['VAL'].'"':"'".$this->data['no_rek']."'";
this one giving an other ORA error,ORA-01756. its means "You tried to execute a statement that contained a string that was not surrounded by two single quotes"
New Error
Error Number: 1722
ORA-01722: invalid number
SELECT NOMER_REKJURNAL as val FROM TBL_MASTER_GUDANG WHERE KODE_GUDANG = 04
Filename: C:/xampp/htdocs/formula/system/database/DB_driver.php
Line Number: 691
Can somebody tell me why my code getting an error after 2days ?
And
How to solve this error?
thank you
After reading lot of post with ORA error, I can solve my problem.
I just need adding " ' ".$val." ' "
$this->data['no_rek'] = ($this->data['no_rek'] =='')?$this->m_dao->getDataOneColumn("NOMER_REKJURNAL","TBL_MASTER_GUDANG","KODE_GUDANG","'".$this->data['kode_gdg']."'")['VAL']:$this->data['no_rek'];

[Microsoft][ODBC driver for Oracle][Oracle]ORA-00911 in VBScript

When I use the query directly it's works, but when I run in it with VBscript this error occurs.
The connection with de DB works.
global_OracleConn = Createobject("ADODB.Connection")
global_OracleConn.Open connectionString
query = "UPDATE DB.TabelX SET X_DT_ = SYSDATE + 360, "_
&"X_Amount_MAX_ID = 100, X_Amount_IN_REQUEST = '1', X_NUM = 15000,"_
&"X_VALUE_LIMIT = 15000, SCORE = 0,
&"WHERE ROW_ID IN (SELECT X_ULTIMA_ID FROM DB.TabelY "_
&"WHERE OU_NUM IN ('"&varID&"'));"
global_OracleConn.Execute(Query)
I tried use others breaklines or put all in one line, but the error still occurs.
There are several issues:
Remove the semicolon at the end from your SQL string
The quoting is wrong. You missed a double quote after SCORE = 0,
Ancient Microsoft ODBC Driver for Oracle is deprecated for ages. Use the ODBC driver from Oracle
Use prepared statement with bind parameters, i.e.

Replace character in pig

My data is in the following format..
{"Foo":"ABC","Bar":"20090101100000","Quux":"{\"QuuxId\":1234,\"QuuxName\":\"Sam\"}"}
I need it to be in this format:
{"Foo":"ABC","Bar":"20090101100000","Quux":{"QuuxId":1234,"QuuxName":"Sam"}}
I'm trying to using Pig's replace function to get it in the format I need..
So, I tried ..
"LOGS = LOAD 'inputloc' USING TextStorage() as unparsedString:chararray;;" +
"REPL1 = foreach LOGS REPLACE($0, '"{', '{');" +
"REPL2 = foreach REPL1 REPLACE($0, '}"', '}');"
"STORE REPL2 INTO 'outputlocation';"
It throws an error.. Unexpected token '{' in expression or statement.
So based on an answer here, I tried:
"REPL1 = foreach LOGS REPLACE($0, '"\\{', '\\{');"
Now, it gives an error.. Unexpected token '\\' in expression or statement.
Any help is sincerely appreciated..
Thanks
Works for me:
REPL1 = FOREACH LOGS GENERATE REPLACE($0, '"\\{', '\\{');
In your code you are missing the GENERATE and the double quotes at the beginning and end are wrong.
Please check the below code.
LOGS = load 'inputlocation' as unparsedString:chararray;
REPL1 = foreach LOGS generate REPLACE($0, '"\\{', '\\{');
REPL2 = foreach REPL1 generate REPLACE($0, '}"', '}');
STORE REPL2 INTO 'outputlocation';
Hope it will work.
Load the data using the delimiter as shown below:
sam = load 'sampledata' using PigStorage(',');
sam1 = foreach sam generate $0,$1,CONCAT(REPLACE($2,'([^A-Za-z0-9:"{]+)',''),REPLACE($3,'([^A-Za-z0-9:"}]+)',''));
This will give you the desired output.
({"Foo":"ABC","Bar":"20090101100000","Quux":"{"QuuxId":1234"QuuxName":"Sam"}"})

run time error '13' type mismatch

I have my query on VB6 which was:
Set Db = DBEngine.OpenDatabase(App.Path & "\sample4nC4.mdb")
Set rs = Db.OpenRecordset("select *from tbl_student;")
Do Until rs.EOF
With ListView1
.ListItems.Add , , rs.Fields("stud_ID")
.ListItems(ListView.ListItems.Count).SubItems(1) = rs.Fields("stud_fname")
.ListItems(ListView1.ListItems.Count).SubItems(2) = rs.Fields("stud_lname")
.ListItems(ListView1.ListItems.Count).SubItems(3) = rs.Fields("stud_address")
.ListItems(ListView1.ListItems.Count).SubItems(4) = rs.Fields("stud_age")
End With
rs.MoveNext
Loop
When I execute this query, there was an error on line 2 says:
Run Time Error '13' Type Mismatch
I really don't get it because when I check the table name, it was correct and yet I cant access the table. Can anybody answer my problem?
Do you have references to ADO and DAO in your project?
If so, look at this Microsoft support article: https://support.microsoft.com/en-us/kb/181542
Do these
Replace your query from 'select *from tbl_student;'
to
'select stud_fname, stud_lname, stud_address, stud_age from tbl_student'
This includes (1. space between '' and 'from' 2. remove ';' 3. specify the field names explicitly)*
Put a breakpoint in the first line your program and step into, if it still fails check which line it's failing.

VBScript to `drop` and `create` new table in microsoft access

I have VBScript to drop and create new table in microsoft access.
My vb script is :
Set dbeng = CreateObject("DAO.DBEngine.120")
strMdbFile = "amw\db_amw.accdb"
Set db = dbeng.OpenDatabase(strMdbFile)
strSql1 = "DROP TABLE amw"
StrSql2 = "SELECT * INTO amw FROM MPN_V WHERE (((Format([tgl_bayar],'yyyy')) Between Format(Now(),'yyyy')-2 And Format(Now(),'yyyy')))"
strSql3 = "DROP TABLE UPDATE"
strSql4 = "SELECT * INTO update FROM UPDATE6 WHERE id="1""
db.Execute(strSql1)
db.Execute(strSql2)
db.Execute(strSql3)
db.Execute(strSql4)
when the script runs the line db.Execute(strSql1) and db.Execute(strSql2), no error Happen. but, when the script runs the line db.Execute(strSql3) and db.Execute(strSql4), error Happen : Expected end of statement, code 800A0401, source Microsoft VBScript compilation error. Please correct my Script? thank you verymuch
The problem is with the number of quotes on the last SQL statement.
strSql4 = "SELECT * INTO [update] FROM UPDATE6 WHERE id="1""
If "id" is an integer, use the following:
strSql4 = "SELECT * INTO [update] FROM UPDATE6 WHERE id=1"
If "id" is a string, use the following:
strSql4 = "SELECT * INTO [update] FROM UPDATE6 WHERE id=""1"""
Doubling the quotes are necessary when working with a string within a string.

Resources