When I attempt to SELECT data from my sqlite3 database and get the value with the node.js module better-sqlite3, I run into issues where the last two digits of the integer I am getting are rounded.
For example, when I get the value
123412341234123412
it is returned as
123412341234123400
I have used the exact same SQL I am using to select the value in DB Browser and it works as I'd expect (without rounding the number), however when I do this in better-sqlite3 it always rounds these.
Here's the code I'm using in better-sqlite:
let getClocked = db.prepare("SELECT messageID FROM clocked WHERE clockedUID = ?").get(id)
console.log(getClocked)
The returned value in the console:
{ messageID: 643562287101116400 }
The value in my database (the same value that was inserted, viewed with DB Browser for SQLite):
643562287101116427
I have also tried using .all(), .iterate(), .pluck() and .raw() instead of/alongside .get() which gave me the same result. Happens with other values in the table as well.
(Here is the SQL I used to create the table):
CREATE TABLE IF NOT EXISTS "clocked" (
"clockedUID" INTEGER NOT NULL UNIQUE,
"time" TEXT NOT NULL,
"messageID" INTEGER,
PRIMARY KEY("clockedUID")
);
New to SQLite and better-sqlite3, so any help is appreciated! Thanks!
Related
PROBLEM:
I know there is a limit to the number of records (2^32 - 1 per Mozilla) that can be returned from IndexedDB, but what about data? I am having a problem with IDBIndex.getAll(), or IDBObjectStore.getAll() for that matter, throwing a generic error whenever the amount of data apparently exceeds a certain size.
"DOMException: The operation failed for reasons unrelated to the database itself and not covered by any other error code."
I am using Firefox, and this has been an issue for a while.
EXAMPLE:
... open the database, etc ...
let index = db.transaction("database").objectStore("myStore").index("myIndex");
let range = IDBKeyRange.lowerBound(100000); // That's just a random number for the example
let results = index.getAll(range);
results.onerror = e => {...};
results.onsuccess = e => {...};
That will always throw an error. But if I change the range to IDBKeyRange.lowerBound(100001), it always works.
TESTS:
If I were to turn lowerBound into upperBound (and change the range), the number of records returned without throwing an error would change, but that number would be consistent. Since not all records have the same amount of data, and the number of records returned in each case is fairly close (19,844 vs 20,188), that seems to support my assertion. The same thing happens if I change the index, just a different number of records.
Edit: I tested the database on another machine and I got a different maximum number of records returned, but that number was consistent as well.
I've also tried closing programs, thinking maybe it's a memory issue, and changing the size of my database by adding or removing a significant number of records, but that has had no effect on the results returned.
As a workaround, I am currently using openCursor() to evaluate each record individually, but that is slower than using getAll() since I want all the data from each record that satisfies the query.
Any ideas what's wrong and how to fix it?
See related problem that was never solved
my objects are saved like this {"5ec801f6c7efb501a06b167f":"hi"} in DB, with userID as key.
return <div>{b.5ec801f6c7efb501a06b167f}</div>;
In this line it's showing an error, because the key starts with an integer.
How to solve this?
Any java script object property should not start with digits. That's why you are facing issue.
if you need value with that id in b use <div>{b['5ec801f6c7efb501a06b167f']}</div>.
I have a domino view with an amount column but some values are empty...and need to be. The problem is that the #Sum works fine until I have an empty value then it stops summing.
eg: if the values are 5,5,"" and 5 I get a sum of 10 and not 15.
I've traced the problem to the #DbLookup which is that it stops building the return array when it encounters a blank value. There is no built in method of dealing with null values.
https://www.ibm.com/support/knowledgecenter/en/SSVRGU_9.0.1/reference/r_wpdr_atfunctions_dblookup_r.html
To make things harder, #dbLookup returns a string if only one is found or an array if more than one are found. If the values are 5,5,"" and 5 it returns an array of 2 values.
var alloc = #Sum(#DbLookup(#DbName(), "SubForms",MainFrmID , "ca_ca_ca_ca_amount"));
if (isNaN(alloc)){
return "$0.00";
}else{
return "$" + alloc.toFixed(2);
}
Can anyone help me refactor the #sum or #DbLookup to allow for empty values? Unfortunately I cannot define any new functions for this solution. The environment is locked down tightly. With a list of values of 5,5,"" and 5 I need a sum of 15.
I would try #Sum(#TextToNumber(#Trim(#Text(#DbLookup(...)))))
I would try
#Sum( #Transform( #Dblookup ( ....
If #DbLookup does not do what you need, you could always iterate over documents or view entries to build the sum.
The flow would be roughly like this:
1. Get a handle to the current database.
2. Get a handle to the "SubForms" view.
3a. Get a view entry collection using using getAllEntriesByKey() with MainFrmID as key, if a view column exists that displays the values you need.
--OR--
3b. Get a document collection using getAllDocumentsByKey() with MainFrmID as key, if no view column exists that displays the values you need.
4. Iterate over the collection to sum up values, using getColumnValues().get(columnNumber) to access the value from each view entry, or getItemValueDouble(fieldName) to access the value from each document.
That way you can easily detect null values and discard them.
I am trying to store a number as a value in Redis key. For example, I want to store a value of 4. and I don't want it to be stored as "4". Why I need this? Because when I retrieve this value back, I will be doing some bitwise op on it. If it stores as "4" (instead of 4), the value actually stored in Redis seems to be 52 (that is... 00110100 instead of 00000100).
You might wonder, why I don't use Redis bitops. The reason is I have to store an array of many bits. I don't want to be doing redis bitops in a loop. I just want to locally create an equivalent array and upload it by calling set command.
In Javascript, I tried doing
redis.set(key, 4)
obviously it didn't work. Then I tried
redis.set(key, "\x04")
This works. But how do I store an array of bytes by converting to this format? What am I missing here?
Internally, if all of the values of a data type are numeric, then the data is stored by its numeric representation. Otherwise, the data is stored as a string. You cannot force Redis to use a specific representation method for a single data point, as far as I know, and anyways - you'll always get the value as a string. You'll need to parse the value yourself and convert it into an integer, float, etc.
I am trying to create a filter function for a web-based app that relies on SQLite for persistent storage. I am trying to use a prepared statement, but it has to be created dynamically based on the number of boxes checked by the user. I have an query created to which I dynamically add ? placeholders (using the suggestion from IN clause and placeholders).
I've gotten as far as creating the correct number of ?s in the correct places, but I cannot figure out how to then add the values to the parameters inside the [...]'s.
When I use a variable that holds all of the parameter values inside the [...], I get an error "number of '?'s in statement string does not match argument string". I've also tried using one variable for each of the sets of placeholders. That did not work, either. I suppose that the number of placeholders is checked against the number of parameters and an error returned before the variables are read.
// just spaced it with returns and removed the +'s and "'s to make it easier to read
var filterQuery = SELECT t1.col1, t1.col2, t1.col3, t2.col2, t3.col2
FROM t1, t2, t3
WHERE t1.col2 = ?
AND t1.col3 IN ( ?, ?, ?)
AND t2.col2 IN ( ?, ?, ?, ?)
code:
db.transaction(function(tx) {
tx.executeSql(
filterQuery,
[/* what do I put in here so that the number of ?s matches with the number of parameters? */],
success,
failure
);
});
How can I dynamically insert the parameters so that they match the number of placeholders and the mismatch error is avoided?
Clarification: I have successfully run the queries without prepared statements. I'm hoping for a solution that will allow me to use them.
(bonus question - will this query do what I am hoping it will do, i.e., grab only the rows that match all the selections that the user has made?)
Thanks in advance!
Fastest way is to use actual parameter values inside your dynamic SQL instead of question marks (?), e.g.
WHERE t1.col2 = 'searchstring'
AND t1.col3 IN ( 12, 23, 24)
AND t2.col2 IN ( 'value', 'onemorevalue', 'x', 'y')