codeigniter update issue You have an error in your SQL syntax - codeigniter

I am getting the error when I am updating
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 '0 = Array WHERE order_id = '11'' at line 1
UPDATE rel_orders_prices SET 0 = Array WHERE order_id = '11'
Filename: modules/admin/models/Booking_model.php
Line Number: 241

You should use backticks for the column name, because it contains only numbers and the value should be within quotes, so this should work:
UPDATE rel_orders_prices SET `0` = 'Array' WHERE order_id = '11'
Identifiers may begin with a digit but unless quoted may not consist solely of digits.
From: https://dev.mysql.com/doc/refman/8.0/en/identifiers.html

try this query in your model file.
function update($order_id,$insertArray){
return $this->db->where('order_id', $order_id)->update('tablename',$insertArray);
}

Use this like,
$this->db->set('save_price',$save_price);
Because column name missing.
If array then,
$this->db->set(array('save_price'=>$save_price));
OR
$this->db->update('rel_orders_prices',array('save_price'=>$save_price));

Related

MS ACCESS table default value code line for autogenerated sequential and unique alphanumeric number

I am new to MS Access and I would like to generate an autogenerated sequential and unique alphanumeric number of the format SYYMM001, SYYMM002, SYYMM003... (ex for 2023 january: S2301001, S2301002, S2301003).
I use MS Access 2016.
I am in my table, in View mode, in the column InvoiceCode in which I want the number to appear, in the general sheet, in Default Value I used the following code:
= "S" & Format(Now(),"yymm") & Format((DCount("[InvoiceID]","InvoiceTable")),"000")
where InvoiceID is the autonumber column and InvoiceTable the name of the table.
This code does not work and generate the following error:
"Unknown function "Dcount" in validation expression or default value on "Invoice Table.InvoiceCode"
I tried another code that I found online which works but instead of giving me a sequential number it generate a random number ex S2301586, S2301236 ...
="S" & Format(Now(),"yymm") & Format(Int(Rnd()*1000),"000")
Would you have a code that would do what I need?
Thanks in advance for your help
You can't set this in the table.
You could try this in your form you use for data entry - in the BeforeInsert event of the form:
Me!InvoiceID.Value = "S" & Format(Date,"yymm") & Format(DCount("*","InvoiceTable"),"000")

How to use MIN() function of postgresql using java code

I need to find the minimum value from a table . How to use that using java.
databaseClient.sql("Select MIN (employee_salary) " +
"from " + schema + ".employee_instances where employee_id =:employeeId")
This gives me error when i execute my code -
ERROR-
"Column name 'employee_salary' does not exist in column names [min]",
#a_horse_with_no_name's comment above helped resolve my problem:
it seems your Java code tries to retrieve a column named employee_salary but your query does not have such a column (only a column named min). You will need a column alias if that is the case: min(employee_salary) as employee_salary

Char to Date in Oracle

I am trying to run a very basic query off of a date which is defined as a char(18) the results for the field show as 07082015 (for 07/08/15).
select *
from ELECT_REMIT_RESP_HDR_FCT b
where b.OFFICE_NBR = '1234' and b.INV_NBR = '123456'
b.CRTD_DT = '07082015'
I have tried the to_date function and was received an error saying month was not valid.
I found the issue though it doesn't seem right, it ran and worked! I just removed the single quotes from the 07082015.

Optional Multi-Value parameter in BIRT

I have a BIRT report that have 4 optional parameters.
startdate; enddate; stringparam and listparam (multi-value parameter).
I followed "bluish" code on this link How do I set a parameter to a list of values in a BIRT report?
and it works if I give either one or all of the value to the parameter. However, when I leave the parameter blank, I got a blank report (which is incorrect result).
This is my query:
select f1,f2,f3,f4
where f1 >= ? -- startdate parameter
or f2 <= ? -- endate paramter
or f4 = ? -- stringparam
and ( f3 in (''/*?listparam*/) )
I did query on my Oracle db to see what parameter is being passed to my query I got 'NULL' as the VALUE_STRING when I leave the parameters values as blank.
Any help is appreciated.
It sounds like you want to occasionally search for records on one to three of the 4 criteria in the parameters.
There are couple ways to do this:
One way is to use like, and set the default parameter value to % which is the wild card. when the parameter runs it returns all values. Be aware this can be problematic if the fields contain null.
or f4 like ?
So you would need to use something similar to below to return null values.
or (f4 is null
or f4 like ?)
I usually prefer to use "All" as my default parameter value, as you can see in the second "and" we look to see if the parameter value is All, if it is all values for PRODUCTTYPEM1.CATEGORY are returned, if it is anything else it looks for the entered valued in the field PRODUCTTYPEM1.CATEGORY.
where PRODUCTTYPEM1.ACTIVE = 't'
and DEVICE2M1.ISTATUS = 'In Use'
and ( 'All' = ?
or PRODUCTTYPEM1.CATEGORY = ?)
For this to work you will need two parameter entries, the first is for All, the second is for any values other then All.
I only have one Category parameter in the report, the second entry looks at the same parameter a second time if the parameter value is not All
The way this works. (expanded explanation by request)
Opening where statement, and simple second criteria for 'In Use'
where PRODUCTTYPEM1.ACTIVE = 't'
and DEVICE2M1.ISTATUS = 'In Use'
The third criteria is two parts set in parenthesis with an OR statement dividing the two parts
and ( 'All' = ?
or PRODUCTTYPEM1.CATEGORY = ?)
If the value of the parameter is All, then the first part of the statement is met, and the query skips everything thing else in the parenthesis. It is like not have the parameter in your SQL query at all.
If the value of the parameter is NOT all, the first part of the statement is not met so the query looks for the parameter value in field PRODUCTTYPEM1.CATEGORY.
Your final query will probably look something like this, though it is problematic in that we have a Default date of 'All', you probably want to use some kind of date for your default value like Jan 1, 1900.
select f1,f2,f3,f4
where f3 in (''/*?listparam*/)
AND ( 'All' = ?
OR f1 >= ?) -- startdate parameter
AND ( 'All' = ?
OR f2 <= ?) -- endate paramter
AND ( 'All' = ?
OR f4 = ?) -- stringparam

Symfony2/Doctrine DQL QueryException

So I'm attempting to do a query on a table that holds two foreign keys. This table basically sets a specific userID to be an "admin" of a specific zoneID in our application my DQL is this:
'SELECT z, zone FROM MLBPBeerBundle:TableZoneAdmins z JOIN z.zoneAdminsZID WHERE z.zoneAdminsPID = '.$userID .'AND zone.zoneId = z.zoneAdminsZID'
I am getting this error:
An exception has been thrown during the rendering of a template ("[Syntax Error] line 0, col 80: Error: Expected end of string, got 'z'") in "MLBPBeerBundle:Profile:index.html.twig" at line 10.
From looking at the query the part in question "line 0, col 80 is the beginning of z.zoneAdminsPID which means at least in my interpretation of the error that it expects the string to end right after the WHERE which makes no sense
What makes this even more confusing is I have already successfully used a similar query to get a team name out of our games table which has a foreign key to the teams id:
'SELECT g, team1 FROM MLBPBeerBundle:TableGame g JOIN g.gameWinnertid WHERE g.gameZoneid = '.$zoneId .'AND team1.id = g.gameWinnertid'
Thank you for any help you can provide this has left me stumped as to me I don't really see a difference in how to two queries operate other than the fact they are grabbing different data
I was able to fix this by not including the JOIN, Symfony is more automagical than I thought in the fact that
SELECT z FROM MLBPBeerBundle:TableZoneAdmins z WHERE z.zoneAdminsPID = '.$userID
From here the zoneAdminsZID was a proper zone Entity, now I believe this is lazily loading this entity aka not firing the query till I "derefence" the ZID but for us this works just fine

Resources