Error when reading from pre-populated SQLite database in Ionic project

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

Error when reading from pre-populated SQLite database in Ionic project

Robert Helmick
I'm receiving an error when I try to read from a pre-populated SQLite
database: `sqlite3_prepare_v2 failure: no such table 'plant'`

From what I understand SQLite looks for the mydb.db file in the /www folder
by default, then creates an empty database when it doesn't find the
pre-populated mydb.db file. This is why it can't find the 'plant' table,
because the newly created blank database obviously doesn't contain a
'plant' table. However I can confirm that the database *is* in the /www
folder, and that it contains the 'plant' table when I run `sqlite3 mydb.db`
then `.tables` in the terminal.

I can't figure out why it's not reading from the pre-populated mydb.db file.

Folder structure (from root):

    /src
    -/app
    --/app.component.ts
    /www
    -/mydb.db

app.component.ts:

      constructor(public platform: Platform, private sqlite: SQLite ) {
        platform.ready().then(() => {
          this.getData();
        });
      }

      getData() {
        this.sqlite.create({
          name: 'mydb.db',
          location: 'default'
        }).then((db: SQLiteObject) => {
          db.executeSql('SELECT * FROM plant ORDER BY id ASC', [])
          .then(res => {
            // Do Stuff
          }).catch(e => console.log("FAIL executeSql:", e));
        })
      }

I've attempted many fixes that I've found on StackOverflow, like wiping the
app from my device, starting a new ionic project then copying app and
config files over, and setting a direct path in the database location, but
it still keeps trying to read from the empty database that it creates..

Thanks in advance for any help.
_______________________________________________
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: Error when reading from pre-populated SQLite database in Ionic project

Simon Slavin-3
On 6 Sep 2018, at 5:33pm, Robert Helmick <[hidden email]> wrote:

> by default, then creates an empty database when it doesn't find the
> pre-populated mydb.db file. This is why it can't find the 'plant' table,
> because the newly created blank database obviously doesn't contain a
> 'plant' table. However I can confirm that the database *is* in the /www
> folder, and that it contains the 'plant' table when I run `sqlite3 mydb.db`

What OS ?
Are you using the C API or some other library ?

If you write code to create a new database (open a filename, do at least a CREATE TABLE command, close the connection) what directory does it put the file in ?

Simon.
_______________________________________________
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: Error when reading from pre-populated SQLite database in Ionic project

Robert Helmick
Hi Simon,

Thanks for your response. I'm using the node.js plugin. I've tried creating
a table then closing the db, and the queries executed successfully, but I
was not able to find the database file that it created. I searched the
folder structure and was unable to find any .db file, even though the db
was opened, a table was created, and the db was closed again.

Regards,
Robert

On Thu, Sep 6, 2018 at 12:32 PM Simon Slavin <[hidden email]> wrote:

> On 6 Sep 2018, at 5:33pm, Robert Helmick <[hidden email]>
> wrote:
>
> > by default, then creates an empty database when it doesn't find the
> > pre-populated mydb.db file. This is why it can't find the 'plant' table,
> > because the newly created blank database obviously doesn't contain a
> > 'plant' table. However I can confirm that the database *is* in the /www
> > folder, and that it contains the 'plant' table when I run `sqlite3
> mydb.db`
>
> What OS ?
> Are you using the C API or some other library ?
>
> If you write code to create a new database (open a filename, do at least a
> CREATE TABLE command, close the connection) what directory does it put the
> file in ?
>
> Simon.
> _______________________________________________
> 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: Error when reading from pre-populated SQLite database in Ionic project

Simon Slavin-3
On 10 Sep 2018, at 12:30am, Robert Helmick <[hidden email]> wrote:

> Thanks for your response. I'm using the node.js plugin. I've tried creating
> a table then closing the db, and the queries executed successfully, but I
> was not able to find the database file that it created. I searched the
> folder structure and was unable to find any .db file, even though the db
> was opened, a table was created, and the db was closed again.

Once you have found the file, you will understand where the default folder is.

Just as a test, after your program which creates the table and puts a row into it is finished, write another to check that the table you created is still there.  If it is, then the file definitely exists somewhere.

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