Getting error "file is encrypted or is not a database" when trying simple C example

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

Getting error "file is encrypted or is not a database" when trying simple C example

Fred Basset
I am using sqlite3 version 2.8.17 on an Arm Debian Linux system.

I created a test table using these commands from Linux:

"
cat 01_create_tables.sql
CREATE TABLE PV_INTERVALDATA (
   timestamp DATE,
   T_ambient      REAL    NOT NULL,
   T_trunk1       REAL    NOT NULL,
   T_trunk4       REAL    NOT NULL
);

sqlite < 01_create_tables.sql pvintervaldata.sqlite
"

I then went to insert a row into the new database with this C code:

"
#include <stdio.h>
#include <sqlite3.h>

static int callback(void *NotUsed, int argc, char **argv, char **azColName){
  int i;
  for(i=0; i<argc; i++){
    printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  }
  printf("\n");
  return 0;
}

int main(int argc, char **argv){
  sqlite3 *db;
  char *zErrMsg = 0;
  int rc;

  rc = sqlite3_open("pvintervaldata.sqlite", &db);
  if( rc ){
    fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    return(1);
  }
  rc = sqlite3_exec(db, "insert into PV_INTERVALDATA
values(datetime('now','localtime'), 24.5, 20, 21);", callback, 0, &zErrMsg);
  if( rc!=SQLITE_OK ){
    fprintf(stderr, "SQL error: %s\n", zErrMsg);
    sqlite3_free(zErrMsg);
  }
  sqlite3_close(db);
  return 0;
}
"

On running the C program I get this error however:

"
SQL error: file is encrypted or is not a database
"

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

Re: Getting error "file is encrypted or is not a database" when trying simple C example

Richard Hipp-3
On Sun, May 25, 2014 at 5:07 PM, Fred Basset <[hidden email]>wrote:

> I am using sqlite3 version 2.8.17 on an Arm Debian Linux system.
>

SQLite version 2 and version 3 have incompatible file formats.  You appear
to have created a database using version 2 then tried to read that database
using version 3.

You should use SQLite version 3 exclusively.  SQLite 3 has been the
standard for 10 years.  SQLite3 is used for everything.  Nobody has used
SQLite2 in a very, very long time.



>
> I created a test table using these commands from Linux:
>
> "
> cat 01_create_tables.sql
> CREATE TABLE PV_INTERVALDATA (
>    timestamp DATE,
>    T_ambient      REAL    NOT NULL,
>    T_trunk1       REAL    NOT NULL,
>    T_trunk4       REAL    NOT NULL
> );
>
> sqlite < 01_create_tables.sql pvintervaldata.sqlite
> "
>
> I then went to insert a row into the new database with this C code:
>
> "
> #include <stdio.h>
> #include <sqlite3.h>
>
> static int callback(void *NotUsed, int argc, char **argv, char
> **azColName){
>   int i;
>   for(i=0; i<argc; i++){
>     printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
>   }
>   printf("\n");
>   return 0;
> }
>
> int main(int argc, char **argv){
>   sqlite3 *db;
>   char *zErrMsg = 0;
>   int rc;
>
>   rc = sqlite3_open("pvintervaldata.sqlite", &db);
>   if( rc ){
>     fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
>     sqlite3_close(db);
>     return(1);
>   }
>   rc = sqlite3_exec(db, "insert into PV_INTERVALDATA
> values(datetime('now','localtime'), 24.5, 20, 21);", callback, 0,
> &zErrMsg);
>   if( rc!=SQLITE_OK ){
>     fprintf(stderr, "SQL error: %s\n", zErrMsg);
>     sqlite3_free(zErrMsg);
>   }
>   sqlite3_close(db);
>   return 0;
> }
> "
>
> On running the C program I get this error however:
>
> "
> SQL error: file is encrypted or is not a database
> "
>
> What is going wrong?
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>



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

Re: Getting error "file is encrypted or is not a database" when trying simple C example

R Smith
In reply to this post by Fred Basset

On 2014/05/25 23:07, Fred Basset wrote:
> I am using sqlite3 version 2.8.17 on an Arm Debian Linux system.

There is no SQLite3 version 2.8.17...  it's either SQLite 2 which may have had a version 2.8.17 or SQLite3 which only ever has
versions 3.n.n.n and for which we still need to get to version 3.8.17 somewhere down the line (current version is only at 3.8.4.n).

So, unless your statement has a typo regarding the version number, you seem to be making DBs in SQLite 2 and trying to open it with
SQLite 3 - which I assume will always fail as the file architecture is different (though I could be wrong, I only ever used SQLite3
and have never actually encountered an SQLite2 or earlier DB in the wild).

If this is the issue, the C makefiles etc. are all easily downloadable from the SQLite site so updating the Linux distro to use a
latest version is easy. If this is a widely deployed thing, it might be less easy, but I can't believe any recent (or even
not-so-recent) Linux distro would still include an SQLite 2 build, unless I'm very uninformed (which might well be).

Source / Build Files can be found at:
http://www.sqlite.org/download.html



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

Re: Getting error "file is encrypted or is not a database" when trying simple C example

Donald Griggs
Hi Fred,

At the risk of informing you of something you may already know,
you should be able to convert an sqlite version 2 database to sqlite3
easily using the command line commands as follows:

sqlite OLD.DB .dump | sqlite3 NEW.DB

http://www.sqlite.org/version3.html


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

Re: Getting error "file is encrypted or is not a database" when trying simple C example

KlaasV
In reply to this post by Fred Basset
FYI: SQLite2.8.17 for some Linux-versions (and Apple ppc) can be found here:
http://www.rpmfind.net/linux/rpm2html/search.php?query=sqlite2

Perhaps there are applications to convert to a more contemporary format like 3.8.4.3

 

Kind regards | Cordiali saluti | Vriendelijke groeten | Freundliche Grüsse,
Klaas `Z4us` V, freelance CIO & ICT-consultant, BCNarTOSit
_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Klaas "Z4us" V, MetaDBA at InnocentIsArt.EU
Reply | Threaded
Open this post in threaded view
|

Re: Getting error "file is encrypted or is not a database" when trying simple C example

Fred Basset
In reply to this post by Donald Griggs
Yes I had done an "apt-get install sqlite" which had installed sqlite2.  I
removed it, installed sqlite3 and all is good now.


On Mon, May 26, 2014 at 8:26 AM, Donald Griggs <[hidden email]> wrote:

> Hi Fred,
>
> At the risk of informing you of something you may already know,
> you should be able to convert an sqlite version 2 database to sqlite3
> easily using the command line commands as follows:
>
> sqlite OLD.DB .dump | sqlite3 NEW.DB
>
> http://www.sqlite.org/version3.html
>
>
> Donald
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users