Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db.lastID is undefined #4

Open
Zvorykin opened this issue Sep 28, 2017 · 9 comments
Open

db.lastID is undefined #4

Zvorykin opened this issue Sep 28, 2017 · 9 comments

Comments

@Zvorykin
Copy link

Zvorykin commented Sep 28, 2017

Code
db.run('INSERT INTO foo ...', function (err) { console.log(err, this.lastID) })
prints null undefined

Using Electron 1.8

What am I doing wrong?

@fritx
Copy link
Owner

fritx commented Oct 4, 2017

@ElectroDr3am hey, are you sure you were using function (err) {} instead of err => {}?

Or have you tried:

stmt = db.prepare('INSERT INTO foo VALUES (?)')
stmt.run(params, err => {
  console.log(err, stmt.lastID)
})

I've just tried cross-sqlcipher in both node and electron, Mac.

(It would take me some time to test it in Windows.)

Ref:

fritx added a commit to fritx/unix-sqlcipher that referenced this issue Oct 4, 2017
@Zvorykin
Copy link
Author

Zvorykin commented Oct 4, 2017 via email

@fritx
Copy link
Owner

fritx commented Oct 4, 2017

Oh you are using electron's remote and Vue stuff, I'm not quite sure.
I suggest you use stmt.lastID syntax. You can try it instead.
See TryGhost/node-sqlite3#622 (comment)

@Zvorykin
Copy link
Author

Zvorykin commented Oct 4, 2017 via email

@fritx
Copy link
Owner

fritx commented Oct 5, 2017

@ElectroDr3am hah.. anyway I have another advice...
Personally I think the logic business (db query) should be placed in the main process,
and you turn off the webPreferences.nodeIntegration in renderer processes.

You can send ipc messages between them, and don't have to use remote.getGlobal,
it could be the ideal model of an electron app?

@Zvorykin
Copy link
Author

Zvorykin commented Oct 6, 2017 via email

@Zvorykin
Copy link
Author

Zvorykin commented Oct 6, 2017 via email

@fritx
Copy link
Owner

fritx commented Oct 7, 2017

@ElectroDr3am does it work for you? with cross-sqlcipher

@Zvorykin
Copy link
Author

Zvorykin commented Oct 13, 2017 via email

fritx added a commit to fritx/unix-sqlcipher that referenced this issue Apr 15, 2018
fritx added a commit to we-demo/sqlcipher-electron-demo that referenced this issue Apr 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants