Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { SQLite } from 'expo'
- async function main() {
- const db = SQLite.openDatabase('mydb')
- console.debug('nn')
- await exec_sql({ db, sql: `DROP TABLE IF EXISTS table_name;` })
- await exec_sql({ db, sql: `CREATE TABLE IF NOT EXISTS table_name (id INTEGER PRIMARY KEY, created_at INTEGER NOT NULL);` })
- await exec_sql({ db, sql: `INSERT INTO table_name (created_at) VALUES (?);`, parameters: [Math.pow(2, (8 * 4) - 1) - 1] })
- await exec_sql({ db, sql: `INSERT INTO table_name (created_at) VALUES (?);`, parameters: [Math.pow(2, (8 * 4) - 1)] })
- // set to 9223372036854775000 as javascript Number.MAX_SAFE_INTEGER means `Math.pow(2, (8 * 8) - 1) - 1`
- // is rounded higher to 9223372036854776000
- await exec_sql({ db, sql: `INSERT INTO table_name (created_at) VALUES (?);`, parameters: [9223372036854775000] })
- // This will error with
- // Error in callNativeModules()
- // Over flow during conversion: 9223372036854776000 (rounding up due to javascript's Number.MAX_SAFE_INTEGER)
- // await exec_sql({ db, sql: `INSERT INTO table_name (created_at) VALUES (?);`, parameters: [Math.pow(2, (8 * 8) - 1)] })
- await exec_sql({ db, sql: `SELECT * FROM table_name;` })
- }
- main()
- function exec_sql ({ db, sql, parameters = [] }) {
- return new Promise((resolve, reject) => {
- db.transaction(tx => {
- console.debug(`Executing ${sql} with parameters: ${parameters}`)
- tx.executeSql(sql, parameters,
- (_, result) => {
- console.debug(`Have result: ${JSON.stringify(result)}`)
- if (result && result.rows && result.rows._array) {
- resolve({ items: result.rows._array })
- } else {
- resolve()
- }
- },
- (_, err) => {
- console.error(`Error during executing sql: `, err)
- reject(err)
- }
- )
- })
- })
- }
- Executing CREATE TABLE IF NOT EXISTS table_name (id INTEGER PRIMARY KEY, created_at UNSIGNED INTEGER NOT NULL); with parameters:
- Executing INSERT INTO table_name (created_at) VALUES (?); with parameters: 2147483647
- Executing INSERT INTO table_name (created_at) VALUES (?); with parameters: 2147483648
- Executing INSERT INTO table_name (created_at) VALUES (?); with parameters: 9223372036854775000
- Executing SELECT * FROM table_name; with parameters:
- Have result: [{"id": 1, "created_at": 2147483647}, {"id": 2, "created_at": -2147483648}, {"id": 3, "created_at": -1024}]
Add Comment
Please, Sign In to add comment