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

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'];

Related

PowerQuery: Getting error info when it's too late to `try`?

Short Version
In PowerQuery, when the error occurs before I'm able to use try, how do I catch an error and get the reason and message strings?
Long Version
In PowerQuery (using Excel if that matters),
OleDb.DataSource(
MyConnectionString,
[Query="SELECT * FROM NonExistingTable"]
)
returns an error. Great. I want that because I'm trying to make a quick and dirty tool that grabs data from multiple tables, but some people don't have access to all tables and who knows what else will happen in the future. However, I want to handle that error so it degrades gracefully, preferably presenting an explanation to the user based on the info within the error.
Therefore, I attempted error handling with try, like so:
try OleDb.DataSource(
MyConnectionString,
[Query="SELECT * FROM NonExistingTable"]
)
and I had expected it to return something like
[
HasError = true,
Error = [
Reason = "OLE DB",
Message = "Invalid object name: 'NonExistingTable'.",
Details = ...
]
]
but instead, what's returned is
[
HasError = false,
Value = Error
]
where Error is an error object containing the information I want.
I had then tried to make a workaround with something like
let
tryRecord = try OleDb.DataSource(MyConnectionString, [Query="SELECT * FROM NonExistingTable"]),
ret = if (tryRecord[HasError]) then
// It's an error
tryRecord
else try
// If Value.Type() doesn't throw an error then tryRecord[Value] isn't an error, so return it.
(if Value.Type(tryRecord[Value]) = null then null else tryRecord)
otherwise
// tryRecord[Value] contains an error!
try error tryRecord[Value]
in
ret
but try error tryRecord[Value] is not unpacking the error object within tryRecord[Value] like I had hoped.
How do I get the reason and message strings from an error object?

#returns throwing error when running locally on docker

I'm trying to return array of asset from transaction. So as per the syntax I have added #returns and #commit(false) in cto file but its throwing error as
✖ Installing business network. This may take a minute...
ParseException: Expected ")", "-", "false", "true", comment, end of
line, number, string or whitespace but "P" found. File
models/org.zcon.healthcare.cto line 370 column 10
Command failed
And when i'm removing the #returns annotation its not throwing any error.
And well its not throwing any error when i'm removing parameter "Patient[]" from #returns annotation.. But it's against the syntax right?
I'm running the application locally using docker swarm.
My docker composer version is v0.19.12
What's wrong? Is this any bug?
In case if you want to see the transaction definition in cto file.
#commit(false)
#returns(Patient[])
transaction SearchPatient{
o String firstName optional
o String lastName optional
}
And in logic file
/**
* Sample transaction
* #param {org.zcon.healthcare.SearchPatient} tx
* #returns{org.zcon.healthcare.Patient[]}
* #transaction
*/
async function SearchPatient(tx){
let queryString = `SELECT org.zcon.healthcare.Patient WHERE (`;
let conditions = [];
if (tx.hasOwnProperty('firstName')) {
var firstName =tx.firstName;
conditions.push(`(firstName == "${firstName}")`)
};
if (tx.hasOwnProperty('lastName')) {
var lastName = tx.lastName;
conditions.push(`(lastName == "${lastName}")`)
};
queryString += conditions.join(' AND ') + ')';
let finalQuery = buildQuery(queryString);
const searchPatient = await query(finalQuery);
if(searchPatient.length ==0){
throw "No Patient Records found!!"
}else
return searchPatient;
}
I've not seen this error with composer network install (deploying to a running Fabric) I did the network install just fine (see screenshot) with your model and code. I suggest that your error may lie elsewhere in your business network ? Can you add the complete sequence of what you got to get the error? How did you build your bna file?
I also tried your code (ending....):
const searchPatient = await query(finalQuery);
console.log("results are " + searchPatient);
console.log("element 1 of array is " + searchPatient[0]);
if(searchPatient.length ==0){
throw "No Patient Records found!!"
} else
return searchPatient;
}
and can see the returned results fine (as shown in console.log - just using a different network name obviously FYI)

ORA-03135: connection lost contact when prepare sql from Perl

I have a problem about connection to database.I execute command line as below:
$Oracle_Dbh = DBI->connect("dbi:Oracle:$two_task", $Oracle_User, $Oracle_Password,
{ RaiseError => 0 , AutoCommit => 0, PrintError => 0});
$HNDL_TABLE = $Oracle_Dbh->prepare("select * from MMSC40_CDR where rownum<=1");
my $err="";
if(!$HNDL_TABLE){
$err = $Oracle_Dbh->errstr;
$exists = 0;
}
if (!$exists){
print "error: $err";
}
Sometimes, it has a error occurred as below:
"error: ORA-03135: connection lost contact Process ID: 8936 Session ID: 1585 Serial number: 27537 (DBD ERROR: error possibly near <*> indicator at char 11 in 'select * fr<*>om MMSC40_CDR where rownum<=1')"
and DBA checked not have any error in listener log from database.
So if anybody can resolve or find out the cause, please tell me.
I do not have setup to test this, but I guess you are getting this error because you have prepared the query but didn't execute it:
$HNDL_TABLE->execute() or die "Couldn't execute query: $Oracle_Dbh->errstr";
Better to use placeholder ? in query preparation and then execute with value:
$HNDL_TABLE = $Oracle_Dbh->prepare("select * from MMSC40_CDR where rownum<=?");
$HNDL_TABLE->execute(1) or die "Couldn't execute query: $Oracle_Dbh->errstr";

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.

Codeigniter concat_ws not working

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.

Resources