PLUA2: double-packing in databases

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

PLUA2: double-packing in databases

krakenarm
Hiho.. ive tried to pack a table into a table.
 after a few misses i got the idea:
t1={1,2,3}
intertable= bin.pack("BBB", t1)
t2={"a", "b", intertable}
datatowrite= bin.pack("SSS", t2)

no problems here.. no errors returned while writing datatowrite into
the DB,
but now i try to open them:

t2= bin.unpack("SSS", dataread)
t1= bin.unpack("BBB", t2[3])

but t1 is not my table t1 it is nil.

I tried the openmodes in binary and normal mode... got the same results.

Reply | Threaded
Open this post in threaded view
|

Re: PLUA2: double-packing in databases

ygfz4v902

How are you writing the DB? This code works for me:

s = bin.pack('SSS', {'a', 'b', bin.pack('BBB', {1, 2, 3})})
db = io.open('db:/testdb', 'w')
db:openrec(db:createrec(string.len(s)))
db:closerec()
db:close()
........
db = io.open('db:/testdb', 'r')
db:openrec(0) --I used Bird to find out I had created record #0
s = db:read('*a')
db:closerec()
db:close()
t2 = bin.unpack('SSS', s)
t1 = bin.unpack('BBB', t2[3])
And I got the original tables back. I also tried this with a stream
database (just omit the createrec, openrec, and closerec lines) and it
worked just the same. This is Plua 2.0b10 on a Zire 31.

I have a feeling somehow your problem has to do with embedded nulls in
the datatowrite string (put there by bin.pack(SSS)), but that's just a
guess.

krakenarm krakenarm-at-yahoo.de |plua| wrote:
>
> Hiho.. ive tried to pack a table into a table.
> after a few misses i got the idea:
> t1={1,2,3}
> intertable= bin.pack("BBB", t1)
> t2={"a", "b", intertable}
> datatowrite= bin.pack("SSS", t2)
>
> no problems here.. no errors returned while writing datatowrite into
> the DB,
> but now i try to open them:
>
> t2= bin.unpack("SSS", dataread)
> t1= bin.unpack("BBB", t2[3])
>
> but t1 is not my table t1 it is nil.
>
> I tried the openmodes in binary and normal mode... got the same results.
>
>

[Non-text portions of this message have been removed]

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Search Ads

Get new customers.

List your web site

in Yahoo! Search.

Curves on Yahoo!

Share & discuss

Curves, fitness

and weight loss.

.

__,_._,___
Reply | Threaded
Open this post in threaded view
|

Re: PLUA2: double-packing in databases

ygfz4v902

Error: proofreading failure at line 3. Expected db:write() call. See below.

ygfz4v902-at-sneakemail.com |plua| wrote:
>
> How are you writing the DB? This code works for me:
>
> s = bin.pack('SSS', {'a', 'b', bin.pack('BBB', {1, 2, 3})})
> db = io.open('db:/testdb', 'w')
> db:openrec(db:createrec(string.len(s)))
> *db:write(s)*
> db:closerec()
> db:close()
> ........
> db = io.open('db:/testdb', 'r')
> db:openrec(0) --I used Bird to find out I had created record #0
> s = db:read('*a')
> db:closerec()
> db:close()
> t2 = bin.unpack('SSS', s)
> t1 = bin.unpack('BBB', t2[3])
> And I got the original tables back. I also tried this with a stream
> database (just omit the createrec, openrec, and closerec lines) and it
> worked just the same. This is Plua 2.0b10 on a Zire 31.
>
> I have a feeling somehow your problem has to do with embedded nulls in
> the datatowrite string (put there by bin.pack(SSS)), but that's just a
> guess.
>
> krakenarm krakenarm-at-yahoo.de |plua| wrote:
> >
> > Hiho.. ive tried to pack a table into a table.
> > after a few misses i got the idea:
> > t1={1,2,3}
> > intertable= bin.pack("BBB", t1)
> > t2={"a", "b", intertable}
> > datatowrite= bin.pack("SSS", t2)
> >
> > no problems here.. no errors returned while writing datatowrite into
> > the DB,
> > but now i try to open them:
> >
> > t2= bin.unpack("SSS", dataread)
> > t1= bin.unpack("BBB", t2[3])
> >
> > but t1 is not my table t1 it is nil.
> >
> > I tried the openmodes in binary and normal mode... got the same results.
> >
> >
>
> [Non-text portions of this message have been removed]
>
>

[Non-text portions of this message have been removed]

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Dog Groups

on Yahoo! Groups

Share pictures &

stories about dogs.

Wellness Spot

Embrace Change

Break the Yo-Yo

weight loss cycle.

.

__,_._,___