Wanting to return REAL as formatted TEXT

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Wanting to return REAL as formatted TEXT

Phoenix
I am trying to retrieve some numeric data from a table using COBOL (not
a 'C' programmer).

sqlite3_column_type says its type '2' so I am using
sqlite3_column_double to return the data. The problem is that the
language I am using does not seem to like REAL numbers as I'm getting a
zero value.

From what I have been able to workout it should be possible to return a
REAL number as a formatted text string, which would make things easier
for me, but am not sure of the details to do it.

I am not looking for somebody to do this, just some breadcrumbs to point
me in the correct direction.

regards, Robert

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Wanting to return REAL as formatted TEXT

John McKown
On Wed, Sep 20, 2017 at 11:01 AM, Phoenix <[hidden email]>
wrote:

> I am trying to retrieve some numeric data from a table using COBOL (not
> a 'C' programmer).
>
> sqlite3_column_type says its type '2' so I am using
> sqlite3_column_double to return the data. The problem is that the
>

​SQLite3 is different from many other RDMS systems. In something like
PostgreSQL, I would do an SQL similar to " SELECT REAL_COLUMN::TEXT FROM
TABLE;" to cas​t the real data to a text value. In SQLite3, you can simply
sue the "sqlite3_column_text" to return the data. The SQLite3 engine will
"cast" the real data to a textual form.

On page: http://sqlite.org/c3ref/column_blob.html , it states:

The first six interfaces (_blob, _double, _int, _int64, _text, and _text16)
each return the value of a result column in a specific data format. If the
result column is not initially in the requested format (for example, if the
query returns an integer but the sqlite3_column_text() interface is used to
extract the value) then an automatic type conversion is performed.



> language I am using does not seem to like REAL numbers as I'm getting a
> zero value.
>
> From what I have been able to workout it should be possible to return a
> REAL number as a formatted text string, which would make things easier
> for me, but am not sure of the details to do it.
>
> I am not looking for somebody to do this, just some breadcrumbs to point
> me in the correct direction.
>
> regards, Robert
>
>
--
*L'Shanah Tovah Tikatevu*

Maranatha! <><
John McKown
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Wanting to return REAL as formatted TEXT

Richard Hipp-3
In reply to this post by Phoenix
On 9/20/17, Phoenix <[hidden email]> wrote:
>
> From what I have been able to workout it should be possible to return a
> REAL number as a formatted text string, which would make things easier
> for me, but am not sure of the details to do it.

Just call sqlite3_column_text() instead of sqlite3_column_double().
SQLite will do the conversion for you automatically.

--
D. Richard Hipp
[hidden email]
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Wanting to return REAL as formatted TEXT

Keith Medcalf
In reply to this post by John McKown

I presume you have the Working Storage declared as COMPUTATIONAL-2?

Which COBOL compiler are you using?


---
The fact that there's a Highway to Hell but only a Stairway to Heaven says a lot about anticipated traffic volume.

>-----Original Message-----
>From: sqlite-users [mailto:sqlite-users-
>[hidden email]] On Behalf Of John McKown
>Sent: Wednesday, 20 September, 2017 10:25
>To: SQLite mailing list
>Subject: Re: [sqlite] Wanting to return REAL as formatted TEXT
>
>On Wed, Sep 20, 2017 at 11:01 AM, Phoenix
><[hidden email]>
>wrote:
>
>> I am trying to retrieve some numeric data from a table using COBOL
>(not
>> a 'C' programmer).
>>
>> sqlite3_column_type says its type '2' so I am using
>> sqlite3_column_double to return the data. The problem is that the
>>
>
>​SQLite3 is different from many other RDMS systems. In something like
>PostgreSQL, I would do an SQL similar to " SELECT REAL_COLUMN::TEXT
>FROM
>TABLE;" to cas​t the real data to a text value. In SQLite3, you can
>simply
>sue the "sqlite3_column_text" to return the data. The SQLite3 engine
>will
>"cast" the real data to a textual form.
>
>On page: http://sqlite.org/c3ref/column_blob.html , it states:
>
>The first six interfaces (_blob, _double, _int, _int64, _text, and
>_text16)
>each return the value of a result column in a specific data format.
>If the
>result column is not initially in the requested format (for example,
>if the
>query returns an integer but the sqlite3_column_text() interface is
>used to
>extract the value) then an automatic type conversion is performed.
>
>
>
>> language I am using does not seem to like REAL numbers as I'm
>getting a
>> zero value.
>>
>> From what I have been able to workout it should be possible to
>return a
>> REAL number as a formatted text string, which would make things
>easier
>> for me, but am not sure of the details to do it.
>>
>> I am not looking for somebody to do this, just some breadcrumbs to
>point
>> me in the correct direction.
>>
>> regards, Robert
>>
>>
>--
>*L'Shanah Tovah Tikatevu*
>
>Maranatha! <><
>John McKown
>_______________________________________________
>sqlite-users mailing list
>[hidden email]
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users



_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Wanting to return REAL as formatted TEXT [SOLVED]

Robert W.Mills
In reply to this post by Phoenix
@Richard & @John,

    Have just tried that and it works just how I wanted it. Will have to
make the same change for the INTEGER columns as well.

@Keith,

    We came to the conclusion that USAGE FLOAT-LONG was the best thing
to use. I then had the problem in deciding what picture to use for the
'edited' field it was moved into. During earlier testing I noticed that
the sqlite3 CLI was outputting the REAL numbers in the format I needed.
Had a look at the source code but as I said "I am not a 'C' programmer"
an got easily lost. Therefore decided I needed to ask for help which I got.

    I'm using GnuCOBOL 2.2


On 20/09/17 17:01, Phoenix wrote:

> I am trying to retrieve some numeric data from a table using COBOL (not
> a 'C' programmer).
>
> sqlite3_column_type says its type '2' so I am using
> sqlite3_column_double to return the data. The problem is that the
> language I am using does not seem to like REAL numbers as I'm getting a
> zero value.
>
> >From what I have been able to workout it should be possible to return a
> REAL number as a formatted text string, which would make things easier
> for me, but am not sure of the details to do it.
>
> I am not looking for somebody to do this, just some breadcrumbs to point
> me in the correct direction.
>
> regards, Robert
>

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users