Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Dynamic Sql Error. Necesito ayuda (https://www.clubdelphi.com/foros/showthread.php?t=58706)

Gabichu 29-07-2008 17:22:19

Dynamic Sql Error. Necesito ayuda
 
Hola!! Soy nueva por aca y llevo menos de un mes programando en delphi por lo tanto cualquier ayuda o sugerencia es bienvenida..

Estoy tratando de agregar el valor en letras de cierto monto

Este es el codigo ahora, ya probé varias cosas y siempre obtengo errores

El error que obtengo es "Dynamic sql errror.Error Code:104 Invalid token"

Código Delphi [-]
modifventa.SQL.Clear;
modifventa.SQL.Add('update venta set procesado=1 where cod_venta='+ventas.Fields[0].AsString);
modifventa.ExecSQL;
f_menu.conex.Commit;
///generar el total en letras
try letras.Numero:=ventas.Fields[5].AsFloat; //total de la factura en guaranies
letras.Moneda:='Guaranies'; //nombre de moneda
letras.Centavos:='Centimos'; //Centimos
letras.Masculino:=true;
//venta.Fields[20].AsString:=letras.AsString;
texto:=letras.AsString; //asiganar el valor a una variable
// showmessage(texto);
finally letras.Free; end ;
//anteriormente probe con esto
{modifventa2.SQL.Clear;
modifventa2.SQL.Add('update venta set TOTLETRAS='+texto+' where cod_venta='+ventas.Fields[0].AsString);
modifventa2.ExecSQL;
f_menu.conex.Commit;} //agregar el total de financiacion en la tabla de ventas
modifventa2.SQL.Clear;
modifventa2.SQL.Add('update venta set TOT_FINANCIACION='
 +floattostr(totFinanc)+',TOTLETRAS='+texto+' where cod_venta='+ventas.Fields[0].AsString);
//se que la porcion de codigo+',TOTLETRAS='+texto+' es la que produce el error ya que si escribo solo esto
//modifventa2.SQL.Add('update venta set TOT_FINANCIACION='
// +floattostr(totFinanc)+' where cod_venta='+ventas.Fields[0].AsString); entonces no hay error
modifventa2.ExecSQL; f_menu.conex.Commit;

creo que di muchas vueltas... ojala puedan ayudarme.. desde ya gracias...

poliburro 29-07-2008 17:38:01

Código Delphi [-]
 
With modifventa do 
  Begin
     // Si cod_venta es alfanumérico debes agregar comilla doble
    SQL. text := 'update venta set procesado=1 where cod_venta='''+ventas.Fields[0].AsString + '''';
   ExecSQL;
   f_menu.conex.Commit;
try 
   letras.Numero:=ventas.Fields[5].AsFloat;
   letras.Moneda:='Guaranies'; 
   letras.Centavos:='Centimos'; 
   letras.Masculino:=true;
   texto:=letras.AsString; 
finally 
   letras.Free; 
end ;

Gabichu 29-07-2008 20:01:27

La linea del problema

Código Delphi [-]
modifventa2.SQL.Add('update venta set TOT_FINANCIACION='+floattostr(totFinanc)+',TOTLETRAS='+texto+' where cod_venta='+ventas.Fields[0].AsString);
La linea corregida
Código Delphi [-]
modifventa2.SQL.Add('update venta set TOT_FINANCIACION='+floattostr(totFinanc)+',TOTLETRAS='''+texto+''' where cod_venta='+ventas.Fields[0].AsString);

Gracias por la ayuda pude resolver mi pequeño inconveniente..
El problema eran las comillas. esto '+texto+' se convirtio en esto '''+texto+''' y asunto solucionado...

Kipow 29-07-2008 20:16:54

Proba utilizar la funcion QuotedStr

Código Delphi [-]

declaracion 

function QuotedStr(const S: string): string;
   description 

Returns the quoted version of a string. A single quote character (') is inserted at the beginning and end of string S, and each single quote character in the string is repeated.     
example 

var s : string;

s:='Delphi''s Pascal';
//ShowMessage returns Delphi's Pascal
s := QuotedStr(s);
//ShowMessage returns 'Delphi''s Pascal'

poliburro 30-07-2008 20:32:42

Cita:

Empezado por Kipow (Mensaje 304182)
Proba utilizar la funcion QuotedStr


Es útil esa función amigo pero yo no la recomiendo y te diré por que.

cuando incrustas pl/sql en delphi de muchas líneas QuotedStr solo añade complejidad al código, en cambio una consulta de muchas líneas correctamente indentada, cuyas cadenas están definidas con comilla doble es mucho más facil de leer.

Experiencia personal amigo.

Saludos

Kipow 31-07-2008 04:58:10

Bueno por experiencia personal la veo mucho mas practica, normalmente cuando necesito mucho codigo PL/SQL utilizo algun componente para trabajar. Pero esto es para que pruebe a usarla y segun el decida si se le complica o no la forma de ver el codigo.

Saludos.


La franja horaria es GMT +2. Ahora son las 15:20:23.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi