A) Check the SQL Gateway log
Set ^%SYSLOG = 3
http://127.0.0.1:1972/csp/docbook/DocBook.UI.Page.cls?KEY=GSQG_C13365
B) Restrictiins
http://127.0.0.1:1972/csp/docbook/DocBook.UI.Page.cls?KEY=GSQG_C13374
C) Have you tried to access the tables using a Stored Procedure?
D) Have you tried something like this ?
INSERT INTO ClassName (Prop1,Prop2,...) SELECT Col1, Col2,.... FROM
TableName WHERE ID BETWEEN X AND Y
Regards
Sukesh Hoogan
Bombay, India
[Enterprise Resource Planning & Business Intelligence]
Some thoughts
A) The problem may be due to the fact you are using cursors, which is an
expensive resource to use, as their use may involve round trips.
B) While using a Stored procedure, you can use While loop to process
each row retrieved.
C) Instead of passing the IDs as the parameters to a non-cursor query,
you may incorporate them in the statement itself
"SELECT whatever FROM Table WHERE ID="_starFrom_" AND ID<"_stop
The better syntax is
".......WHERE ID BETWEEN "_startFrom_" AND "_stop
Regards
Sukesh Hoogan
Bombay, India
[Enterprise Resource Planning & Business Intelligence]
You must also be aware that it is best to use the ANSI SQL syntax when
talking to one DB from another.
Regards
Sukesh
Bombay, India
[Enterprise Resource Planning & Business Intelligence]
Set startFrom=0,stop=100
set query= %Library.ResultSet()
set ok=query.Prepare("select ID, Location from SatNav.GpsAddress where
ID>"_startFrom_" and ID<"_stop)
If 'ok quit ;some error - more elegant error logging would be
appropriate....
set ok= query.Execute()
If 'ok quit ;some error
While (query.Next()) {
;store data into cache using query.Data("ID"), etc
}
k query
Mark
"kevin furze" <ke...@oakbeam.co.uk> wrote in message
news:a94f1f4e-d32d-4db7...@l28g2000prd.googlegroups.com...
Mark
"Mark Sires" <msi...@geeteeeee.net> wrote in message
news:47fe3...@info2.kinich.com...
> Kevin,
> Which version of Cache are you using. Since you indicate that in the
> 'execute SQL function' without the variable substitution, it works in the
> browser, then the problem is either the embedded SQL processing, or a
> problem with the variable substitution in the embedded SQL.
> I would try using the %Library.ResultSet() class instead, as I would guess
> that is what the system manager SQL execute is using:
>
> Set startFrom=0,stop=100
> set query= %Library.ResultSet().%New()
In general I have been abandoning embedded SQL in favor of the %ResultSet
class - The queries seem to run better, and it isn't prone to the problems
I've encountered with embedded SQL, particularly cursors. Changing a 'row'
that is in the set of rows in your cursor was generally a bad bad thing,
even if the field changed wasn't in the scope of the where clause. Since
the %ResultSet seems to always retrieve the list of rows into a temporary
global, changing one of them doesn't have the same impact. Of course, if
you have a BIG set of id's returned, the %ResultSet can have its own
problems.
Mark
"kevin furze" <ke...@oakbeam.co.uk> wrote in message
news:8a1ed19d-cd55-49c2...@i36g2000prf.googlegroups.com...
I don't profess to fully understand what goes on under the covers, but I
have generally found %ResultSet to give better (more reliable) results than
&sql these days. In your particular situation, I think the reason is that
&sql with a cursor is making a call over the ODBC driver each time you do a
fetch, and the cursor based fetch wasn't working over ODBC. Using
%ResultSet with a dynamic query in this case makes a single call over ODBC
and retrieves all 100 rows.
There may be cases where %ResultSet doesn't retrieve the entire query in a
single call, but that seems to be its 'preferred' behavior, so in cases like
yours, where the return set is small, and the cost of each call is high, it
works better.
&SQL with a cursor seems to 'prefer' to walk through the table directly,
rather than pulling the matching row id's into a temporary storage area. In
some cases this is good, in other cases, not so much. If it hasn't chosen a
good index to use in traversing the table (do not use -> in your where
clause, it will always choose poorly), each 'Fetch' can be slow. If the
data changes while it is 'walking', it can cause unexpected behavior. And
if you use another &SQL statement to update the same table while in the
cursor loop, very unexpected behavior can sometimes occur. On a much older
version, I tracked that problem down to the reuse of some variable names in
the generated code if the same table was used in 2 &SQL - they may have
fixed that in subsequent releases. I changed my techniques to always use
the cursor to retrieve the rows to look/modify, and then do any updates
after closing the cursor, so I haven't worried about whether it has been
changed or not. This is also why %ResultSet frequently works better for me,
the generated code basically does what I was doing to retrieve the matching
rows into a temporary storage area.
Another technique I use to avoid some of the runtime penalties (which really
aren't much) of %Resultset is to put frequently used Static (or simple
variable substitution) queries in a class, then use that query instead of
%DynamicQuery. Using your query as an example, this could be the query
class:
Class MyStuff.queries [ Abstract ]
{
Query GPSData(StartValue As %BigInt = 0, StopValue As %BigInt = 100) As
%SQLQuery(CONTAINID = 1)
{
select ID, Location from SatNav.GpsAddress where ID>:StartValue and
ID<:StopValue
}
}
Then to use it :
Set query=##class(%ResultSet).%New("MyStuff.queries")
s ok=query.Execute(0,100)
The rest is pretty much the same.
If you are using the same query over and over again, this is more efficient
because the query is 'precompiled', and the code lives in the routines
generated by the class compilation, not in every routine it is used in.
Also, if you need to tweak the query, you have one place to fix it. Of
course, the downside, if you tweak it, you can break all the places that use
it.
Mark
"kevin furze" <ke...@oakbeam.co.uk> wrote in message
news:9267f69c-c2dc-44d0...@b1g2000hsg.googlegroups.com...