thanks for the notes. After change "double infinity" to
std::numeric_limits<double>(), here is the output:
1.100000e+00
inf
-inf
3.300000e+00

it is clear that the sqlite3 does store "infinity", and select statement can
retrieve it as well. The "printf" of C++ prints "infinity" as literal "inf".

Michael Chen



On Tue, Oct 20, 2009 at 12:20 AM, John Crenshaw <johncrens...@priacta.com>wrote:

> Sorry, I think I gave you slightly buggy instructions. I just realized
> that max() should be the max true value capable of being stored, which
> should be less than the infinity value. std::numeric_limits<double>
> provides another function named infinity() for getting positive
> infinity. I believe this value will be different than max().
>
> Sorry for the mistake.
>
> John
>
> -----Original Message-----
> From: sqlite-users-boun...@sqlite.org
> [mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Michael Chen
> Sent: Monday, October 19, 2009 11:40 PM
> To: General Discussion of SQLite Database
> Subject: Re: [sqlite] Infinity
>
> Thanks John. After incorporate a few changes, the code can compile and
> run.
> The result seems reasonable, the input infinity
> std::numeric_limits<double>::max() is sent to and retrieved from a
> sqlite3
> database correctly.
>
> --terminal output
>
> sqlite3 tempdb
>
> sqlite> select * from tl;
> 1.1
> 1.79769313486232e+308
> -1.79769313486232e+308
> 3.3
>
>
> --source code --
>
> #include <limits>
> #include <string>
> #include <iostream>
> #include <cassert>
> #include <sqlite3.h>
> using namespace std;
>
> int main(){
> double infinity =   std::numeric_limits<double>::max();
> double ninfinity =  - std::numeric_limits<double>::max();
>  sqlite3 *db;
>  char *zErrMsg = 0;
>  int rc;
>  rc = sqlite3_open("tempdb", &db);
>  if( rc ){
>    fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
>    sqlite3_close(db);
>    exit(1);
>  }
>
>  sqlite3_stmt* create_tl;
>  rc = sqlite3_prepare_v2(db, "create table tl (number real)", -1,
> &create_tl,NULL);
>
>  if ( rc != SQLITE_OK) exit(rc);
>  rc = sqlite3_step(create_tl);
>  if ( rc != SQLITE_DONE) exit(rc);
>
>  sqlite3_stmt* insert_tl;
>  rc = sqlite3_prepare_v2(db,"insert into tl values(:number)",-1,
> &insert_tl,NULL);
>  if ( rc != SQLITE_OK) exit(rc);
>
>  sqlite3_bind_double(insert_tl, 1, 1.1);
>  rc = sqlite3_step(insert_tl);
>  if (rc != SQLITE_DONE)
>    exit(rc);
>
>  sqlite3_reset(insert_tl);
>  sqlite3_bind_double(insert_tl, 1, infinity);
>  rc = sqlite3_step(insert_tl);
>  if (rc != SQLITE_DONE)
>    exit(rc);
>
>  sqlite3_reset(insert_tl);
>  sqlite3_bind_double(insert_tl, 1, ninfinity);
>  rc = sqlite3_step(insert_tl);
>  if (rc != SQLITE_DONE)
>    exit(rc);
>
>  sqlite3_reset(insert_tl);
>  sqlite3_bind_double(insert_tl, 1, 3.3);
>  rc = sqlite3_step(insert_tl);
>  if (rc != SQLITE_DONE)
>    exit(rc);
>
>
>  sqlite3_stmt* select_tl;
>  rc = sqlite3_prepare_v2(db, "select * from tl",-1,&select_tl,NULL);
>  if (rc != SQLITE_OK)
>    exit(rc);
>
>  while ( sqlite3_step(select_tl) == SQLITE_ROW){
>    printf("%e",sqlite3_column_double(select_tl,0));
>    printf("\n");
>  }
>
>  if (rc != SQLITE_DONE)
>    exit(rc);
>  sqlite3_finalize(select_tl);
>
>  sqlite3_close(db);
>  printf("exit normally\n");
> }
>
>
>
>
> --
> Best regards,
> Michael Chen
> Google Voice Phone.: 847-448-0647
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>



-- 
Best regards,
Michael Chen
Google Voice Phone.: 847-448-0647
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to