problem with SQL INSERT [solved]

problem with SQL INSERT [solved]

Postby MOISES » Fri Mar 20, 2020 9:18 am

Hi,

I can´t compile this code:

Code: Select all  Expand view
 

LOCAL cTabla      := company("ITEMS")

  aSql := SQL INSERT INTO &cTabla ( CODIGO, DESCRIPCIO, IMPORTE ) VALUES ( 'C01', 'CONCEPTO PARA PRUEBAS', 12.12 )
   SQLEXEC( aSQL )
 


Thank you.
Last edited by MOISES on Thu Apr 02, 2020 2:59 pm, edited 1 time in total.
Saludos / Regards,

FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
MOISES
 
Posts: 838
Joined: Wed Aug 22, 2007 10:09 am

Re: problem with SQL INSERT

Postby nageswaragunupudi » Fri Mar 20, 2020 9:57 am

Code: Select all  Expand view
LOCAL cTabla      := company("ITEMS")


Please change it as
Code: Select all  Expand view
PRIVATE cTabla      := company("ITEMS")
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: problem with SQL INSERT

Postby MOISES » Fri Mar 20, 2020 10:09 am

Sorry, not working.
Saludos / Regards,

FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
MOISES
 
Posts: 838
Joined: Wed Aug 22, 2007 10:09 am

Re: problem with SQL INSERT

Postby MOISES » Wed Mar 25, 2020 9:53 am

Any fix, please?
Saludos / Regards,

FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
MOISES
 
Posts: 838
Joined: Wed Aug 22, 2007 10:09 am

Re: problem with SQL INSERT

Postby Jack » Wed Mar 25, 2020 11:27 am

Hi,
With MSSQL i do this :

csql:="INSERT INTO "+(cTabla)+ " (PATID,LASTNAME) VALUES ("
cSql:=cSql+" 'C01', 'CONCEPTO PARA PRUEBAS'+" )"

TRY
oCon:Execute(cSql)
CATCH oErr
ShowAdoEr( oCon,csql )
END TRY

Hope it will help !

Philippe
Jack
 
Posts: 288
Joined: Wed Jul 11, 2007 11:06 am

Re: problem with SQL INSERT

Postby MOISES » Wed Mar 25, 2020 11:39 am

Thank you.

The advantage of such command is that it handles the sintax for every Database. So the same code will work under MSSQL, MySQL, Oracle...
Saludos / Regards,

FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
MOISES
 
Posts: 838
Joined: Wed Aug 22, 2007 10:09 am

Re: problem with SQL INSERT

Postby mgsoft » Sat Mar 28, 2020 6:25 pm

Maybe this could be:

Code: Select all  Expand view
#xtranslate ADO_SQL UPDATE  [TABLE <tbl> ] SET [ <col1> = <val1> [,<colN> = <valN> ] ] [ WHERE <*cwhere*> ]  => ;
   "UPDATE " + <tbl> + " SET " + ;
   FW_ArrayAsList( \{  FW_QuotedColSQL( <"col1"> ) + " = " +  FW_ValToSQL( <val1> ) ;
   [,  FW_QuotedColSQL( <"colN"> ) + " = " + FW_ValToSQL( <valN> )  ] \} ) [ + " WHERE " + CharRepl( '"', <"cwhere">, "'", .t. ) ]
Saludos,

Eduardo
User avatar
mgsoft
 
Posts: 422
Joined: Mon Aug 17, 2009 12:18 pm
Location: España

Re: problem with SQL INSERT

Postby nageswaragunupudi » Tue Mar 31, 2020 7:10 am

MOISES wrote:Sorry, not working.


Code: Select all  Expand view
  local cSql
   local cName    := "John"
   local cCity    := "New York"
   local dHireDate:= Date() - 1200
   local nSalary  := 123023.75

   PRIVATE cTable := "customer"

   cSql := SQL INSERT INTO &cTable ( FIRST, CITY, HIREDATE, SALARY ) VALUES ( cName, cCity, dHireDate, nSalary )
   ? cSql
 


Image

INSERTING MULTIPLE ROWS:

Code: Select all  Expand view
  local cSql
   local aData    := ;
      {  { "John",  "New York", Date() - 1200, 23465.55 } ;
      ,  { "Jimmy", "Sydney",   Date() - 2000, 32000.00 } ;
      ,  { "David", "Manila",   Date() - 4000, 54234.76 } ;
      }

   PRIVATE cTable := "customer"

   cSql := SQL INSERT INTO &cTable ( FIRST, CITY, HIREDATE, SALARY ) ARRAY aData
   ? cSql
 


Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: problem with SQL INSERT

Postby MOISES » Wed Apr 01, 2020 11:04 am

Hi,

Hope you are doing well.

There is a typo on calling TABLE. I fixed as follows:

#xtranslate SQL INSERT INTO [TABLE <tbl> ] ( <cols,...> ) ARRAY <a> => ;
"INSERT INTO " + <tbl> + " ( " + FW_QuotedColSQL( #<cols> ) + " ) " + " VALUES " + ;
StrTran( StrTran( FW_ValToSql( AClone( <a> ) ), '( (', '(' ), ') )', ')' )

It now works with local variables.
Saludos / Regards,

FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
MOISES
 
Posts: 838
Joined: Wed Aug 22, 2007 10:09 am

Re: problem with SQL INSERT

Postby nageswaragunupudi » Wed Apr 01, 2020 11:20 am

But we can not change because that breaks the existing code many users are already using.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: problem with SQL INSERT

Postby MOISES » Wed Apr 01, 2020 12:02 pm

Thank you.

I will create my own function with regular INSERT.

How can I transform all the data in an array into VALUES with FW_ValToSQL?
Saludos / Regards,

FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
MOISES
 
Posts: 838
Joined: Wed Aug 22, 2007 10:09 am

Re: problem with SQL INSERT

Postby nageswaragunupudi » Wed Apr 01, 2020 1:19 pm

Please study the existing translates in the fwsqlcmd.ch
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: problem with SQL INSERT

Postby MOISES » Wed Apr 01, 2020 3:59 pm

Thank you. I used FW_AdoApplyParams.

I would like to take this opportunity to thank you for the enormous usefulness of the ADO functions you have created, which make our work much easier. Congratulations once again.
Saludos / Regards,

FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
MOISES
 
Posts: 838
Joined: Wed Aug 22, 2007 10:09 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 33 guests