I have an internal intranet made in PHP and we had the Oracle server here, but it has been moved to an cloud server. Since that I'm having an issue.
If I execute a simple query from PHP like "select * from empresas" it executes normal, but if I try a more complicated query, with some joins and where clause, it gives the error ORA-03113. Trying to execute from PL/SQL Developer, this specific query takes something like 5 seconds to execute, it returns something like 15 rows only.
I have no acces to the Oracle logs, because this cloud is just one instance to us.
I think that maybe is a PDO configuration or maybe version that I need to configure/check to solve this problem, just don't know how to start.
The old Oracle server was a Windows server and the Oracle version was 12. The cloud is Oracle 11 and is a Linux server.
Here is the query:
`SELECT distinct
ct.descricao MARCA,
e.nome EMPRESA,
vi.cod_item CODIGO,
i.descricao DESCRICAO,
igi.cod_grupo_interno CODTIPO,
igi.descricao TIPO,
ic.cod_curva CLASSEABC,
v.cod_cliente COD_CLIENTE,
cd.nome NOME_CLIENTE,
ci.descricao CID_CLIENTE,
ci.uf UF_CLIENTE,
CASE WHEN cd.cpf<>' ' THEN 'F' ELSE 'J' END TIPO_CLIENTE,
cl.descricao DESCTP_CLIENTE,
SUM(vi.qtde) QTDE,
vi.preco_unitario PPUBLICO,
SUM(vi.qtde * vi.preco_unitario) FAT_BRT,
SUM(vi.TOTAL_DESCONTOS) DESCONTO,
SUM(vi.preco_liquido_final) FAT_LIQ,
SUM(vi.qtde * vi.preco_contabil) CUSTO,
SUM(vi.base_icms) BASE_ICMS,
SUM(vi.valor_icms) VLR_ICMS,
'0' VLR_COP,
'0' ACRESCIMO,
SUM(vi.valor_pis + vi.valor_cofins) VLR_PCOF,
SUM(vi.valor_ipi) VLR_IPI,
NULL VLR_MARGEM,
v.controle|| '-' || v.serie NF,
TO_CHAR(v.emissao, 'DD/MM/YYYY') DTNF,
n.cod_natureza CODNATUREZA,
n.descricao NATUREZA,
eu.id_funcionario VENDEDOR,
eu.nome_completo FUNCIONARIO,
eu.nome LOGIN,
eu.cod_funcao TIPO_FUN,
'N' STATUS,
v.numero_os OS,
v.chassi_resumido VEICULO,
cd.bairro BAIRRO_CLIENTE,
v.controle|| '-' || v.serie NOTA,
pg.descricao CONDICAO_PG,
pg.cod_forma_pgto COD_CONDICAO,
os.tipo CD_TP_OS,
ost.descricao DS_TP_OS,
'0' PERCUSTOOPER,
ed.cod_empresa_departamento DEPARTAMENTO,
ic.custo_fornecedor VLRREPOSICAO
FROM vendas v
INNER JOIN venda_itens vi ON vi.cod_empresa = v.cod_empresa and vi.controle = v.controle
INNER JOIN itens_custos ic ON ic.cod_empresa = v.cod_empresa AND ic.cod_item = vi.cod_item AND ic.cod_fornecedor = vi.cod_fornecedor
INNER JOIN itens_fornecedor if ON if.cod_item = vi.cod_item AND if.cod_fornecedor = vi.cod_fornecedor
INNER JOIN fornecedor_estoque fe ON fe.cod_fornecedor = if.cod_fornecedor
INNER JOIN itens i ON i.cod_item = vi.cod_item
INNER JOIN itens_grupo_interno igi ON igi.cod_grupo_interno = i.cod_grupo_interno
INNER JOIN empresas e ON e.cod_empresa = v.cod_empresa
INNER JOIN empresas_usuarios eu ON eu.nome = v.vendedor
INNER JOIN empresas_funcoes ef ON ef.cod_funcao = eu.cod_funcao
INNER JOIN empresas_departamentos ed ON ed.cod_empresa = v.cod_empresa AND ed.cod_empresa_departamento = v.cod_empresa_departamento
INNER JOIN parm_sys p ON p.cod_empresa = v.cod_empresa
INNER JOIN concessionaria_tipo ct ON ct.cod_tipo_concessionaria = p.tipo_concessionaria
INNER JOIN cliente_diverso cd ON cd.cod_cliente = v.cod_cliente AND cd.cod_empresa = v.cod_empresa
INNER JOIN clientes_tipo cl ON cl.cod_tipo = cd.cod_tipo
INNER JOIN cidades ci ON ci.cod_cidades = cd.cod_cidades
LEFT JOIN pagamento_venda pv ON pv.controle = v.controle AND pv.serie = v.serie
LEFT JOIN forma_pgto pg ON pg.cod_forma_pgto = pv.cod_forma_pgto
LEFT JOIN os ON os.cod_empresa = v.cod_empresa and os.numero_os = v.numero_os
LEFT JOIN os_tipos ost ON ost.tipo = os.tipo
LEFT JOIN natureza n ON n.cod_natureza = vi.cod_natureza and n.grupo = vi.grupo
LEFT JOIN operacoes ops ON ops.cod_empresa = v.cod_empresa and ops.cod_operacao = v.cod_operacao
WHERE v.status <> '1' AND v.total_produtos > 0
AND (ops.grupo is null or ops.grupo = 2)
AND v.emissao >= to_date(SYSDATE-20)
AND i.COD_GRUPO_INTERNO <> 13
GROUP BY ct.descricao, e.nome, vi.cod_item, i.descricao, igi.cod_grupo_interno, igi.descricao, ic.cod_curva, v.cod_cliente,
cd.nome, ci.descricao, ci.uf, CASE WHEN cd.cpf<>' ' THEN 'F' ELSE 'J' END, cl.descricao, vi.preco_unitario, vi.preco_contabil,
v.margem, v.controle|| '-' || v.serie, TO_CHAR(v.emissao, 'DD/MM/YYYY'), n.cod_natureza, n.descricao, eu.id_funcionario,
eu.nome_completo, eu.nome, eu.cod_funcao, v.numero_os, v.chassi_resumido, cd.bairro, v.controle|| '-' || v.serie,
pg.descricao,pg.cod_forma_pgto, os.tipo, ost.descricao, ed.cod_empresa_departamento, ic.custo_fornecedor`
I asked the administers for Oracle logs, it gave me nothing, the administers saw that my query even got to there, then I tried a lot of things and finally my boss found an answer. He saw that the problem is the size of the package the PHP are sending through the VPN connection we have with the cloud. So the solution (at least for now) is add to PDO connection the size we need using: "(DESCRIPTION=(SDU=1400) ..." on the connection string.
Related
I'm trying to update multiple joined tables in codeigniter but it is giving the following error:
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 '.carro_id INNER JOIN a ON ac.atributo_id = a.id INNER JOIN
m ON c.`modelo_' at line 1
UPDATE `carro c, atributo_carro ac, atributos a, modelos m, marcas ma
INNER JOIN ac ON c`.`id = ac`.`carro_id INNER JOIN a ON
ac`.`atributo_id = a`.`id INNER JOIN m ON c`.`modelo_id = m`.`id INNER
JOIN ma ON m`.`marca_id =` `ma`.`id` SET `marcas`.`marca` = 'Opel',
`modelos`.`modelo` = 'AMmmmmm', `carro`.`kilometragem` = '12000',
`carro`.`cor` = 'Azul', `carro`.`ano` = '1992', `carro`.`descricao` =
'dfghjk', `carro`.`valor` = '1288.00', `atributos`.`atributo` =
'rapido' WHERE `carro`.`id` = '10'
This is my function to update.
public function update_carro_query($id, $data)
{
// print_r($data); die();
$query =
$this->db->set('marcas.marca', $data['marca']);
$this->db->set('modelos.modelo', $data['modelo']);
$this->db->set('carro.kilometragem', $data['kilometragem']);
$this->db->set('carro.cor', $data['cor']);
$this->db->set('carro.ano', $data['ano']);
$this->db->set('carro.descricao', $data['descricao']);
$this->db->set('carro.valor', $data['valor']);
$this->db->set('atributos.atributo', $data['atributo']);
$this->db->where('carro.id', $id);
$this->db->update('carro c, atributo_carro ac, atributos a, modelos m, marcas ma INNER JOIN ac ON c.id = ac.carro_id INNER JOIN a ON ac.atributo_id = a.id INNER JOIN m ON c.modelo_id = m.id INNER JOIN ma ON m.marca_id = ma.id');
return $query;
}
This is my database tables and relationships
The query is generated by the function. What can be causing the syntax error? Am i missing something?
The update() method only expects a table name as first parameter, not a complete statement including a join and more. So it'll wrap the first parameter into backticks. This leads to the sql syntax error you have.
Better use query() to generate your (not straightforward) update statement.
I have this following SQL Query
SELECT *
FROM inventory_audits
WHERE id in (
SELECT distinct inventory_audits.id
FROM inventory_audits
LEFT JOIN pick_lists ON (pick_lists.number = substr(inventory_audits.reference,0,8))
LEFT JOIN pick_list_items ON (pick_list_items.pick_list_id = pick_lists.id)
LEFT JOIN load_plan_items ON (load_plan_items.load_plan_id = pick_list_items.load_plan_id)
LEFT JOIN sales_order_items ON (load_plan_items.sales_order_item_id = sales_order_items.id)
LEFT JOIN invoices ON (invoices.id = sales_order_items.invoice_id)
WHERE inventory_adjustment_reason_description = 'Picked'
AND (invoices.number = '230367' OR invoices.number = '230368')
)
And, I need to convert this to propel which results as
$cr = new Criteria();
$cr->addJoin(PickListPeer::ID, PickListItemPeer::PICK_LIST_ID);
$cr->addJoin(PickListItemPeer::LOAD_PLAN_ID, LoadPlanItemPeer::LOAD_PLAN_ID);
$cr->addJoin(LoadPlanItemPeer::SALES_ORDER_ITEM_ID, SalesOrderItemPeer::ID);
$cr->addJoin(SalesOrderItemPeer::INVOICE_ID, InvoicePeer::ID);
$cr->add(InventoryAuditPeer::INVENTORY_ADJUSTMENT_REASON_DESCRIPTION, 'Picked');
$cr->add(InvoicePeer::NUMBER, $invoiceNumbers, Criteria::IN);
$cr->setDistinct(true);
But I'm kinda confused how I can convert this join in propel...
LEFT JOIN pick_lists ON (pick_lists.number =
substr(inventory_audits.reference,0,8))
, I tried this but not working..
$cr->add(PickListPeer::NUMBER, substr(InventoryAuditPeer::REFERENCE,
0, 8));
I am using propel 1.2.1
Any references are appreciated :) tyvm..
Nvm, I got it working by using this line..
$cr->addJoin('substr(inventory_audits.REFERENCE, 0, 8)', PickListPeer::NUMBER, Criteria::LEFT_JOIN);
I have 8 tables in my database and I need to have all necessary data in one query from them.
when i run the query in mysql on localhost return true results (12 rows) but when i run that in mysql on linux server return just one last row...
My query is:
SELECT `mhr_patients`.`id`,
`mhr_patients`.`fullName`,
`mhr_patients`.`nationalCode`,
`mhr_patients`.`age`,
`mhr_patients`.`firstGCS`,
`mhr_patients`.`fileNumber`,
`mhr_patients`.`isUnKnown`,
`mhr_patients`.`docDetail`,
`mhr_patients`.`presentation`,
`mhr_patients`.`appRegisterTime`,
`mhr_patients`.`inspectorRegisterTime`,
`mhr_patients`.`patientStatusDetail`,
`mhr_patients`.`patientDetail`,
`mhr_patients`.`status`,
`docT`.`text` AS docText,
`tolOp`.`name` AS tolOpName,
`tolOp`.`color` AS tolOpColor,
`tolOp`.`res1` AS tolOpTextColor,
`pLog`.`breathing`,
`pLog`.`bodyMovement`,
`pLog`.`faceMovement`,
`pLog`.`gag`,
`pLog`.`cough`,
`pLog`.`cornea`,
`pLog`.`pupil`,
`pLog`.`dollEye`,
`pLog`.`secondGCS`,
`pLog`.`sedation`,
`pLog`.`inspector`,
`pLog`.`status` As pLogStatus,
`pLog`.`section`,
`pLog`.`id` AS pLogId,
`pLog`.`typeOfSection`,
`pLog`.`lastUpdateTime`,
`pLog`.`isTransfer`,
`pLog`.`opu`,
`hos`.`name` AS hosName,
`mhr_opu`.`name` AS opuName,
`mhr_opu`.`id` AS opuId,
`mhr_states`.`name` AS cityName,
`mhr_inspectors`.`name` AS insName
FROM (`mhr_patients`)
JOIN `mhr_doc` AS docT ON `docT`.`id` = `mhr_patients`.`doc`
JOIN `mhr_tol_options` AS tolOp ON `tolOp`.`id` = `mhr_patients`.`patientStatus`
JOIN `mhr_patients_log` AS pLog ON `pLog`.`pId` = `mhr_patients`.`id` AND pLog.id = (SELECT MAX(mhr_patients_log.id) FROM mhr_patients_log WHERE mhr_patients_log.pId = mhr_patients.id)
JOIN `mhr_hospitals` AS hos ON `hos`.`id` = `pLog`.`hospital`
JOIN `mhr_opu` ON `mhr_opu`.`id` = `pLog`.`opu`
JOIN `mhr_states` ON `mhr_states`.`id` = `pLog`.`city`
JOIN `mhr_inspectors` ON `mhr_inspectors`.`id` = `pLog`.`inspector`
WHERE
`mhr_patients`.`status` = 5
GROUP BY `pLog`.`pId`
ORDER BY `mhr_patients`.`inspectorRegisterTime` asc
LIMIT 30
what is the problem?
i change
JOIN `mhr_inspectors` ON `mhr_inspectors`.`id` = `pLog`.`inspector`
to
LEFT JOIN `mhr_inspectors` ON `mhr_inspectors`.`id` = `pLog`.`inspector`
and my problem was solved. :)
I'm working with a mysql query to select data from multiple tables using LEFT OUTER JOIN. Now i get the following error when i exequte the query:
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 'wg.werkbon_global_id = wk.werkbon_klant_globalid LEFT OUTER
JOIN users AS u' at line 16
Only the problem is that i can't find out what's wrong with my query.
PHP Query:
$query = '
SELECT
wg.werkbon_global_id AS id,
wg.werkbon_global_status AS status,
wg.werkbon_global_date_lastedit AS date,
usr.user_firstname AS monteur_vn,
usr.user_insertion AS monteur_tv,
usr.user_lastname AS monteur_an,
wg.werkbon_global_type AS type,
wg.werkbon_global_layout AS layout,
wg.werkbon_global_werkzaamheden AS werkzaamheden,
wg.werkbon_global_opmerkingen AS opmerkingen,
wk.werkbon_klant_nummer AS klantnr
FROM
werkbon_klant AS wk
LEFT OUTER JOIN werkbon_global AS wg
wg.werkbon_global_id = wk.werkbon_klant_globalid
LEFT OUTER JOIN users AS usr
usr.user_id = wg.werkbon_global_monteur_finish
WHERE
wk.werkbon_klant_nummer = '.$db->Quote($klantid).'
ORDER BY id ASC;
$result = $db->loadAssoc($query);
I think my problem has something todo with left outer join but what?
You are missing the ON operator in your joins!
The correct syntax for a join is:
SELECT * FROM x LEFT JOIN y ON condition WHERE...
$query = "
SELECT
wg.werkbon_global_id AS id,
wg.werkbon_global_status AS status,
wg.werkbon_global_date_lastedit AS date,
usr.user_firstname AS monteur_vn,
usr.user_insertion AS monteur_tv,
usr.user_lastname AS monteur_an,
wg.werkbon_global_type AS type,
wg.werkbon_global_layout AS layout,
wg.werkbon_global_werkzaamheden AS werkzaamheden,
wg.werkbon_global_opmerkingen AS opmerkingen,
wk.werkbon_klant_nummer AS klantnr
FROM
werkbon_klant AS wk
LEFT OUTER JOIN werkbon_global AS wg
wg.werkbon_global_id = wk.werkbon_klant_globalid
LEFT OUTER JOIN users AS usr
usr.user_id = wg.werkbon_global_monteur_finish
WHERE
wk.werkbon_klant_nummer = '.$db->Quote($klantid).'
ORDER BY id ASC";
$result = $db->loadAssoc($query);
Make sure there isn't missing quote
Problem soved thanks to arkascha
The fixed query is now:
$query = '
SELECT
wg.werkbon_global_id AS id,
wg.werkbon_global_status AS status,
wg.werkbon_global_date_lastedit AS date,
usr.user_firstname AS monteur_vn,
usr.user_insertion AS monteur_tv,
usr.user_lastname AS monteur_an,
wg.werkbon_global_type AS type,
wg.werkbon_global_layout AS layout,
wg.werkbon_global_werkzaamheden AS werkzaamheden,
wg.werkbon_global_opmerkingen AS opmerkingen,
wk.werkbon_klant_nummer AS klantnr
FROM
werkbon_klant AS wk
LEFT OUTER JOIN werkbon_global AS wg ON
wg.werkbon_global_id = wk.werkbon_klant_globalid
LEFT OUTER JOIN users AS usr ON
usr.user_id = wg.werkbon_global_monteur_finish
WHERE
wk.werkbon_klant_nummer = '.$db->Quote($klantid).'
ORDER BY id ASC';
$result = $db->loadAssoc($query);
#fred i don't need to add quotes by column names. You only need to add quotes by string/blob values.
#johny my $db->Quote() function will add qoutes automaticly. I don't need to add them and put everything in quote's.
Thanks all for help.
I am currently refactoring a legacy application and converting piece by piece over to zend framework 1.12.
I am scratching my head as to how to convert this over to zend db, is there a way that this can be done in one query?
Right now I see that it fetches a list of folders first and then runs an additional query per folder...
Running this as one query will improve performance, right?
$folders_query = DB::Query("select * from contacts_folders order by sort_order, name");
while($folders = DB::FetchArray($folders_query)){
$counts_total = DB::QueryOne("SELECT count(cm.messages_id) AS total
FROM contacts_basics cb, contacts_messages cm
WHERE cb.contacts_id = cm.contacts_id
AND cm.folders_id = '" . $folders['folders_id'] . "'
AND cm.status = '1'
AND cm.mark = '0'");
if ($counts_total >0){
$folders_name = '<strong>' . $folders['name'] . ' (' . $counts_total . ')</strong>';
} else {
$folders_name = $folders['name'];
}
echo '<li><a href="messages.php?fID=' . $folders['folders_id'] . '">';
echo $folders_name;
echo '</a></li>';
}
Yes, you can do both in the same query
SELECT cf.*, count(cm.messages_id) AS total
FROM contacts_folders cf left outer join
contacts_messages cm
on cf.id = cm.folders_id and
cm.status = '1' AND cm.mark = '0' left outer join
contacts_basics cb
on cb.contacts_id = cm.contacts_id
group by cf.folders_id
order by cf.sort_order, cf.name;
This uses a left outer join to be sure that you get all folders, even if there are no messages (which is how the original code works). Because of the left outer join, the conditions need to be moved into on clauses.
It also fetches all the information from the folders as well as the total. If there are no messages, then it should return 0 for that folder.
There was a minor bug in Gordon's answer but I figured it out thanks to him.
I changed
contacts_basics cb left outer join
To:
left outer join contacts_basics cb
The following code works as expected:
public function getMenuCounts(){
$raw = "SELECT cf.*, count(cm.messages_id) AS total
FROM contacts_folders cf left outer join
contacts_messages cm
on cf.folders_id = cm.folders_id and
cm.status = '1' AND cm.mark = '0'
left outer join contacts_basics cb
on cb.contacts_id = cm.contacts_id
group by cf.folders_id
order by cf.sort_order, cf.name;";
$db = Zend_Db_Table::getDefaultAdapter();
$stmt = $db->query($raw);
return $stmt->fetchAll();
}