[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Saving symbolic variables in a database
From: |
Olaf Till |
Subject: |
Re: Saving symbolic variables in a database |
Date: |
Thu, 10 Mar 2016 09:25:19 +0100 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
On Wed, Mar 09, 2016 at 10:05:53AM -0800, diego9j wrote:
> Hi,
>
> First of all, I might be a little bit colloquial in my explanations (I
> recently started programming in Octave), but I hope that there's no problem
> in that.
>
> As a part of a bigger project, I need to store a symbolic variable (from
> symbolic package) into a postgres database (with database package). I got
> one idea of how to do it but I'm having some trouble that I can't solve, so
> both new ideas and solutions for my problem are welcome.
>
> Since there's no "direct" way of storing symbolic variables in postgres, I
> thought about storing the binary data of the variable, something like:
>
> binary_data=save("-binary","-","symbolic_variable_name");
> 8bit_data=uint8(binary_data);
>
> Then I store it with pq_exec_params as bytea postgres type. The problem is
> that
> 1 - I found no function to parse back from 8-bit to binary
> 2 - I don't know how to make that binary data a variable again
>
> When doing simple file i/o, you save the binary to a file and then with the
> "load" function, the variable "pops out" again, but I don't know how to do
> that with an octave string.
I wasn't aware of the "-" feature of 'save', it seems to be a new
addition, specific to Octave. But as I see it, there might be some
issues:
- Saving "-binary" into a string seems not the right thing to me,
e.g. it will break if the binary data contains a zero byte. Maybe
better if Octave would save into an uint8-array if saving binary?
- A 'symmetric' operation -- loading from a variable -- should be
provided, but seemingly isn't currently available.
I don't quite understand your item '1 - I found no function to parse
back from 8-bit to binary' -- char() would convert from uint8 back to
a string, but I don't see that this would help you.
It's nice to see someone using the database package. But it wasn't
designed to store _arbitrary_ Octave variables into a database. But if
there really is such a need, maybe the database package itself should
provide a way, as long as there is no satisfying possibility with
Octaves save/load. Some functions like 'var2bytea' and
'bytea2var'. I'd guess I could add these within a few days, if really
necessary ...
Olaf
--
public key id EAFE0591, e.g. on x-hkp://pool.sks-keyservers.net
signature.asc
Description: Digital signature