|
| Query params array seems to disappear |
 |
Thu, 2 Aug 2007 07:47:08 -0500 |
I am trying to implement the use of replaceable paramters and it is giving
me some problems.
In this case the associative params array seems to disappear, but I am not
sure why? I have included some code above the crash just so you can see
that I have set up the query. But go to the bottom and see where the code
fails.
//Just the setup here, skip to below
qt = new QUERY()
qt.database = db
qt.sql = [select * from "time" ]
qt.sql += [where (empNoDate >= :cLow and empNoDate <= :cHigh) ]
qt.sql += [order by location,last,first]
qt.prepare( )
qt.params[ "cLow" ] = "start value"
qt.params[ "cHigh" ] = "end value"
qt.active = true
oCGI.streamHeader('Missing Time')
oCGI.StreamBody()
oCGI.streamFooter()
Class MyCGISession of CGISession from "sqlWebClass.cc"
function streamBody
******************************************
//just checking if qt.rowset.fields is visible
test_for_qt = qt.rowset.fields["EMPNODATE"].value
//qt.params still ok before the "with (this.fOut)"
qt.params[ "cLow" ] = "some value"
***************************************
with (this.fOut)
******************************************
//qt.rowset.fields still visible here
test_for_qt = qt.rowset.fields["EMPNODATE"].value
// CRASH occurs here. qt.params no longer exists
qt.params[ "cLow" ] = "new start value"
//Error: Data type mismatch. Expecting: Object
***************************************
Why is the qt.rowset still visible but not the qt.params? How can this be
remedied?
|
| Post Reply
|
| Re: Query params array seems to disappear |
 |
Thu, 2 Aug 2007 08:35:41 -0500 |
Michael,
Thanks but still no luck
This option:
p = qt.params
with (this.fOut)
p[ "cLow" ] = .....
endwith
//gave me "Data type mismatch. Expecting: Array"
This option:
this.fOut.qt.params[ "cLow" ] = ....
//gave "Data type mismatch. Expecting: Object"
I don't know how to implement your 3rd option to do without
"with/endwith",
as that is what I learned in your online course on writing response pages
for my web apps.
I even tried to trim the value being placed in the the p["cLow"],
which of
course was furtile.
Claus
"Michael Nuwer" <michael@forget.it> wrote in message
news:j2EhbnQ1HHA.1688@news-server...
>
> Hello Claus,
>
>
> Claus Mygind wrote:
>> with (this.fOut)
>>
>> ******************************************
>> //qt.rowset.fields still visible here
>> test_for_qt = qt.rowset.fields["EMPNODATE"].value
>>
>> // CRASH occurs here. qt.params no longer exists
>> qt.params[ "cLow" ] = "new start value"
>
>
> You can use only memory variables inside a with/endwith statement (on the
> left side of an assignment or equality). In your code the "with"
> statements make the line this:
>
> this.fOut.qt.params[ "cLow" ] = ....
>
> qt.params still exists, but your code is not referencing it.
>
> You could try something like this:
>
> p = qt.params
> with (this.fOut)
> p[ "cLow" ] = .....
> endwith
>
> Or do not use the with/endwith statements.
>
>
>>
>> //Error: Data type mismatch. Expecting: Object
>> ***************************************
>> Why is the qt.rowset still visible but not the qt.params? How can this
>> be remedied?
>>
|
| Post Reply
|
| Re: Query params array seems to disappear |
 |
Thu, 02 Aug 2007 09:18:07 -040 |
Hello Claus,
Claus Mygind wrote:
> with (this.fOut)
>
> ******************************************
> //qt.rowset.fields still visible here
> test_for_qt = qt.rowset.fields["EMPNODATE"].value
>
> // CRASH occurs here. qt.params no longer exists
> qt.params[ "cLow" ] = "new start value"
You can use only memory variables inside a with/endwith statement (on
the left side of an assignment or equality). In your code the "with"
statements make the line this:
this.fOut.qt.params[ "cLow" ] = ....
qt.params still exists, but your code is not referencing it.
You could try something like this:
p = qt.params
with (this.fOut)
p[ "cLow" ] = .....
endwith
Or do not use the with/endwith statements.
>
> //Error: Data type mismatch. Expecting: Object
> ***************************************
> Why is the qt.rowset still visible but not the qt.params? How can this be
> remedied?
>
|
| Post Reply
|
| Re: Query params array seems to disappear |
 |
Thu, 02 Aug 2007 12:09:45 -040 |
Claus Mygind wrote:
> Michael,
>
> Thanks but still no luck
> This option:
> p = qt.params
> with (this.fOut)
> p[ "cLow" ] = .....
> endwith
> //gave me "Data type mismatch. Expecting: Array"
Ah, yes. Sorry about that. This is a bug which I forgot about.
Associative arrays have problems inside with/endwith
>
> This option:
> this.fOut.qt.params[ "cLow" ] = ....
> //gave "Data type mismatch. Expecting: Object"
>
> I don't know how to implement your 3rd option to do without
"with/endwith",
> as that is what I learned in your online course on writing response pages
> for my web apps.
Make code like this:
with (this.fOut)
x = qt.rowset.fields["Name"].value
puts( x )
qt.params[ "RowID" ] = 4
qt.requery()
x = qt.rowset.fields["Name"].value
puts( x )
endwith
Into code like this:
with (this.fOut)
x = qt.rowset.fields["Name"].value
puts( x )
endwith
qt.params[ "RowID" ] = 4
qt.requery()
with (this.fOut)
x = qt.rowset.fields["Name"].value
puts( x )
endwith
I have attached a turn-key. Save all the code to ONE prg file and run it.
a = new myTest()
a.doTest()
class myTest
this.OpenOut()
function doTest
db = new database()
with ( db )
databaseName = "DBASESAMPLES"
active = true
endwith
qt = new QUERY()
qt.database = db
qt.sql = [select * from "fish" ]
qt.sql += [where id >= :RowID]
//qt.prepare( )
qt.params[ "RowID" ] = 2
qt.active = true
with (this.oOut)
x = ""+qt.rowset.fields["ID"].value
x += space(5)
x += qt.rowset.fields["Name"].value
puts( x )
endwith
qt.params[ "RowID" ] = 4
qt.requery()
with (this.oOut)
x = ""+qt.rowset.fields["ID"].value
x += space(5)
x += qt.rowset.fields["Name"].value
puts( x )
endwith
this.oOut.close()
run(true, "notepad.exe MyTest.txt")
function OpenOut
this.oOut = new file()
this.oOut.create("MyTest.txt")
|
| Post Reply
|
| Re: Query params array seems to disappear |
 |
Thu, 2 Aug 2007 12:31:32 -0500 |
Thanks Michael
I used a slightly different twist to get around the problem. But it's good
to know it had to do with the array.
To requery, I simply branched to a function
class
function steamBody()
with
class::getNewRowSet()
endwith
return true
function getNewRowSet()
q.params["p1"] = "new value"
q.requery()
q.rowset.first()
return true
endclass
"Michael Nuwer" <michael@forget.it> wrote in message
news:ly9MVHS1HHA.776@news-server...
> Claus Mygind wrote:
>> Michael,
>>
>> Thanks but still no luck
>> This option:
>> p = qt.params
>> with (this.fOut)
>> p[ "cLow" ] = .....
>> endwith
>> //gave me "Data type mismatch. Expecting: Array"
>
> Ah, yes. Sorry about that. This is a bug which I forgot about. Associative
> arrays have problems inside with/endwith
>
>>
>> This option:
>> this.fOut.qt.params[ "cLow" ] = ....
>> //gave "Data type mismatch. Expecting: Object"
>>
>> I don't know how to implement your 3rd option to do without
>> "with/endwith", as that is what I learned in your online
course on
>> writing response pages for my web apps.
>
> Make code like this:
>
> with (this.fOut)
> x = qt.rowset.fields["Name"].value
> puts( x )
> qt.params[ "RowID" ] = 4
> qt.requery()
> x = qt.rowset.fields["Name"].value
> puts( x )
> endwith
>
> Into code like this:
>
> with (this.fOut)
> x = qt.rowset.fields["Name"].value
> puts( x )
> endwith
>
> qt.params[ "RowID" ] = 4
> qt.requery()
>
> with (this.fOut)
> x = qt.rowset.fields["Name"].value
> puts( x )
> endwith
>
>
> I have attached a turn-key. Save all the code to ONE prg file and run it.
>
>
> a = new myTest()
> a.doTest()
>
> class myTest
> this.OpenOut()
>
> function doTest
>
> db = new database()
> with ( db )
> databaseName = "DBASESAMPLES"
> active = true
> endwith
>
>
> qt = new QUERY()
> qt.database = db
> qt.sql = [select * from "fish" ]
> qt.sql += [where id >= :RowID]
> //qt.prepare( )
> qt.params[ "RowID" ] = 2
> qt.active = true
>
>
> with (this.oOut)
> x = ""+qt.rowset.fields["ID"].value
> x += space(5)
> x += qt.rowset.fields["Name"].value
> puts( x )
> endwith
> qt.params[ "RowID" ] = 4
> qt.requery()
> with (this.oOut)
> x = ""+qt.rowset.fields["ID"].value
> x += space(5)
> x += qt.rowset.fields["Name"].value
> puts( x )
> endwith
>
> this.oOut.close()
> run(true, "notepad.exe MyTest.txt")
>
> function OpenOut
> this.oOut = new file()
> this.oOut.create("MyTest.txt")
>
>
> endclass
|
| Post Reply
|
|
|
|
|
|
|
|
|
|