Re: sqlexec() with multiple SQL commands

From: Alan C. Sheffield (_at_)
Date: 11/01/04


Date: Mon, 1 Nov 2004 18:07:16 -0500

AH! Now I see.

If you look close at the original code you'll see with that line break it
would not work at all in VFP. so mentally I removed it. I see stuff like
that and assume that the news/e-mail client wrapped the line.

Alan

"Anders Altberg" <x_pragma@telia.com> wrote in message
news:%23OnbcWEwEHA.344@TK2MSFTNGP10.phx.gbl...
> Hi Alan
> This is how the original appears to me in Outlook Express
>
> m_query = 'insert into table_a (field_a) values (100); select
> @@identity;'
>
> with a line break after the word select. That, as I see it, will not work
> without a ; after the word select, like this:
> m_query = 'insert into table_a (field_a) values (100); select ;
> @@identity;'
> The ; would be a VFP line continuation character. If his string is
orginally
> all in one line, then it's technically correct and should work.
> If it doesn't work you can pick up the OSDB C error in AERROR(arrayname)
> -Anders
>
> "Alan C. Sheffield" <asheffield @ park west gallery.com> wrote in message
> news:enn68TCwEHA.2196@TK2MSFTNGP14.phx.gbl...
> > I understand the advantages to using the TEXT - ENDTEXT.
> >
> > The thing I am missing is the difference in the original SQL and what
you
> > posted. If the difference is not the pleasance of the line break, what
> would
> > make yours work and the original not work. I can not see where the
> resulting
> > string would be different.
> >
> > I know I have to have missed something.
> >
> > OR are you saying that the difference is in the construction of the
string
> > and I should not expect to see the difference but that SQL Server will?
> >
> > Alan
> > "Anders Altberg" <x_pragma@telia.com> wrote in message
> > news:eBRhrP6vEHA.200@TK2MSFTNGP11.phx.gbl...
> > > Hi Alan
> > > The advantage of using TEXT - ENDTEXT [NOSHOW} [TEXTMETRGE] for
queries
> > is
> > > , as I see it, that you can get rid of all the quote character and +
and
> ;
> > > in a concatenated chain. Simpler to read, simpler to write, for
yourself
> > and
> > > for future programmer revisiting the code. It also means you can copy
> and
> > > paste queries from textbooks, SQL Server samples or newsgroups without
> > much
> > > editing. Your queries will look exactly as a SQL Server programmer's
> code
> > > would.
> > >
> > > -Anders
> > >
> > > "Alan C. Sheffield" <asheffield @ park west gallery.com> wrote in
> message
> > > news:uvGMX7bvEHA.3612@TK2MSFTNGP09.phx.gbl...
> > > > OK, I guess I messed something then. What's the effective difference
> > > between
> > > > Randy's original code and your example. I do not see that the result
> > would
> > > > be different other than the link breaks.
> > > >
> > > > Alan
> > > >
> > > > "Anders Altberg" <x_pragma@telia.com> wrote in message
> > > > news:e2JpbRUvEHA.2520@TK2MSFTNGP15.phx.gbl...
> > > > > You don't have to separate SQLServer commands on separate lines.
> thew
> > ;
> > > > > shows is the end-of-command chrarcter. It's confusing of course
that
> > for
> > > > VFP
> > > > > the ; is a line continuation charachter and chr(1# is th end of
> > command
> > > > > this works in q query sent to SQLServer as a one-line string
> > > > > lcSQL = [select * from customers; insert into customers
(lastname)
> > > values
> > > > > ('x') ; delete from customers where lastname = 'x';]
> > > > > or in VFP with 2 line breaks
> > > > > lcSQL = [select * from customers; insert ;
> > > > > into customers (lastname) ;
> > > > > values ('x') ; delete ;
> > > > > customers where lastname = 'x';]
> > > > > SQLEXEC(h, lcsql)
> > > > >
> > > > > or using TEXT - ENDTEXT
> > > > > TEXT TO lcSQL NOSHOW
> > > > > select * from customers; insert into
> > > > > customers (lastname) values ('x') ; delete
> > > > > from customers where lastname = 'x';
> > > > > ENDTEXT
> > > > > SQLEXEC(h, lcSQL)
> > > > >
> > > > > -Anders
> > > > >
> > > > > "Alan C. Sheffield" <asheffield @ park west gallery.com> wrote in
> > > message
> > > > > news:e2Dm7pPvEHA.2616@TK2MSFTNGP10.phx.gbl...
> > > > > > could you get the same result by just inserting a chr(13) into
the
> > sql
> > > > > > string?
> > > > > >
> > > > > > m_query = 'insert into table_a (field_a) values (100);'
> > > > > > +chr(13)+' select @@identity;'
> > > > > >
> > > > > > m_retcode = sqlexec(m_handle,m_query,"cursor10")
> > > > > >
> > > > > >
> > > > > > Alan
> > > > > > "Anders Altberg" <x_pragma@telia.com> wrote in message
> > > > > > news:u2LjuI9tEHA.2192@TK2MSFTNGP14.phx.gbl...
> > > > > > > Hi Randy
> > > > > > > TEXT TO lcSQL NOSHOW
> > > > > > > insert into table_a (field_a) values (100);
> > > > > > > select
> > > > > > > @@identity;
> > > > > > > ENDTEXT
> > > > > > > s=SQLEXEC(conn, lcSQL, 'retval')
> > > > > > >
> > > > > > > SQLServer will ignore the linbreaks in the text
> > > > > > > -Anders
> > > > > > >
> > > > > > > <rmbyers@magma.ca> wrote in message
> > > > > > > news:34b8n01jqdm65381n6ciklbqjvtgn936r0@4ax.com...
> > > > > > > > Hello,
> > > > > > > >
> > > > > > > > I want to send two SQL commands to the SQL server with just
> one
> > > > > > > > SQLEXEC() call. I believe this should be possible, but it
> > doesn't
> > > > > > > > appear to work.
> > > > > > > >
> > > > > > > > Here is the code:
> > > > > > > >
> > > > > > > > m_query = 'insert into table_a (field_a) values (100);
select
> > > > > > > > @@identity;'
> > > > > > > >
> > > > > > > > m_retcode = sqlexec(m_handle,m_query,"cursor10")
> > > > > > > >
> > > > > > > >
> > > > > > > > ** notice the semicolon separating the two SQL commands in
> > m_query
> > > > > > > >
> > > > > > > > I would expect to get a cursor back containing a field named
> > "exp"
> > > > > > > > which would be the identity value for table_a (which has an
> > > identity
> > > > > > > > column named "id")
> > > > > > > >
> > > > > > > > Any ideas would be appreciated.
> > > > > > > >
> > > > > > > > Thanks
> > > > > > > > Randy
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > >
> > > >
> > >
> >
> >
>



Relevant Pages

  • Re: Exact match using INLIST()
    ... VFP InList() function can be a little confusing ... InList respects the Set Ansi setting ... To avoid this confusion (and to make your SQL ... It's not that the statement behaves differently, but that string ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Embedded SQL and comments
    ... VFP doesn't support -- for comments anywhere. ... as a string to some other backend, I can't say; ... I'll copy the entire sql block to a new area/line, ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Select - SQL vs. SUM
    ... If you have to use an earlier version of VFP earlier than 9, ... >> also force VFP to read from the buffer with a new clause in the SQL ... >> The SELECT command doesn't move the record pointer in the grid's record ... >>> I have a grid whose recordsource is a table named _payments. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: SQL2000 data access via OLEDB
    ... We were having some issues with VFP with SQL 2000. ... Is it true ADO is needed to wrap access via OLEDB, ...
    (microsoft.public.fox.programmer.exchange)
  • Re: moving corporate database out of vfp
    ... I had thought MS Access may have had extensions to VBA to give it a data ... ROBUST APPS are written with VFP as front end and MS-SQL Server as the ... SQL Coding is already built-in to VFP, so if you know it already, and I do ...
    (microsoft.public.fox.programmer.exchange)