SQLite GetString - Specified Cast is not Valid
I'm using SQLite on my mobile game for several years, and am having a recurring exception in production (couldn't reproduce locally, or inspect the database that has this issue) which I cant solve. This exception is being thrown by hundreds of different players, so it's probably not an isolated case of database corruption.
The table in question has only 2 columns: _id (int) and mycol (text), created by this command:
CREATE TABLE mytable ( _id INTEGER PRIMARY KEY, mycol TEXT ) ;
The exception is caused when I try to read the elements on the table with these 2 commands executed sequentially:
A) DELETE FROM mytable WHERE mycol IS NULL OR trim(mycol) = '' ;
B) SELECT mycol FROM mytable ORDER BY _id DESC ;
And then the crash is on the line:
string myColValue = rs.GetString(0);
With the following exception/stacktrace:
InvalidCastException: Specified cast is not valid.
Mono.Data.Sqlite.SqliteDataReader.VerifyType (System.Int32 i, System.Data.DbType typ)
Mono.Data.Sqlite.SqliteDataReader.GetString (System.Int32 i)
Note that the command "A" above is already my attempt at "fixing" the problem, but it is still crashing.
I dont know what else to try - what kind of data would cause that exception? If it was null, the "A" command would avoid it, and if it was any other kind of data it could be cast into string without a problem.
Any ideas?
One relevant info is that the SQLite driver/dll I was using until recently was VERY OLD (from ~2013), so maybe those players getting the crash are old players in which the database and/or table in question was created with this older DLL, and maybe the DB format isn't well supported anymore? If so, any suggestions on how could I detect this so I can drop/recreate the table?
Thanks
sqlite sqlite3
add a comment |
I'm using SQLite on my mobile game for several years, and am having a recurring exception in production (couldn't reproduce locally, or inspect the database that has this issue) which I cant solve. This exception is being thrown by hundreds of different players, so it's probably not an isolated case of database corruption.
The table in question has only 2 columns: _id (int) and mycol (text), created by this command:
CREATE TABLE mytable ( _id INTEGER PRIMARY KEY, mycol TEXT ) ;
The exception is caused when I try to read the elements on the table with these 2 commands executed sequentially:
A) DELETE FROM mytable WHERE mycol IS NULL OR trim(mycol) = '' ;
B) SELECT mycol FROM mytable ORDER BY _id DESC ;
And then the crash is on the line:
string myColValue = rs.GetString(0);
With the following exception/stacktrace:
InvalidCastException: Specified cast is not valid.
Mono.Data.Sqlite.SqliteDataReader.VerifyType (System.Int32 i, System.Data.DbType typ)
Mono.Data.Sqlite.SqliteDataReader.GetString (System.Int32 i)
Note that the command "A" above is already my attempt at "fixing" the problem, but it is still crashing.
I dont know what else to try - what kind of data would cause that exception? If it was null, the "A" command would avoid it, and if it was any other kind of data it could be cast into string without a problem.
Any ideas?
One relevant info is that the SQLite driver/dll I was using until recently was VERY OLD (from ~2013), so maybe those players getting the crash are old players in which the database and/or table in question was created with this older DLL, and maybe the DB format isn't well supported anymore? If so, any suggestions on how could I detect this so I can drop/recreate the table?
Thanks
sqlite sqlite3
Is the DELETE failing because of Referential Integrity? Could you add the WHERE to B and use one query instead of two? Is it possible the query is not returning any rows? Context free comment :)
– DinoCoderSaurus
Nov 21 '18 at 14:21
add a comment |
I'm using SQLite on my mobile game for several years, and am having a recurring exception in production (couldn't reproduce locally, or inspect the database that has this issue) which I cant solve. This exception is being thrown by hundreds of different players, so it's probably not an isolated case of database corruption.
The table in question has only 2 columns: _id (int) and mycol (text), created by this command:
CREATE TABLE mytable ( _id INTEGER PRIMARY KEY, mycol TEXT ) ;
The exception is caused when I try to read the elements on the table with these 2 commands executed sequentially:
A) DELETE FROM mytable WHERE mycol IS NULL OR trim(mycol) = '' ;
B) SELECT mycol FROM mytable ORDER BY _id DESC ;
And then the crash is on the line:
string myColValue = rs.GetString(0);
With the following exception/stacktrace:
InvalidCastException: Specified cast is not valid.
Mono.Data.Sqlite.SqliteDataReader.VerifyType (System.Int32 i, System.Data.DbType typ)
Mono.Data.Sqlite.SqliteDataReader.GetString (System.Int32 i)
Note that the command "A" above is already my attempt at "fixing" the problem, but it is still crashing.
I dont know what else to try - what kind of data would cause that exception? If it was null, the "A" command would avoid it, and if it was any other kind of data it could be cast into string without a problem.
Any ideas?
One relevant info is that the SQLite driver/dll I was using until recently was VERY OLD (from ~2013), so maybe those players getting the crash are old players in which the database and/or table in question was created with this older DLL, and maybe the DB format isn't well supported anymore? If so, any suggestions on how could I detect this so I can drop/recreate the table?
Thanks
sqlite sqlite3
I'm using SQLite on my mobile game for several years, and am having a recurring exception in production (couldn't reproduce locally, or inspect the database that has this issue) which I cant solve. This exception is being thrown by hundreds of different players, so it's probably not an isolated case of database corruption.
The table in question has only 2 columns: _id (int) and mycol (text), created by this command:
CREATE TABLE mytable ( _id INTEGER PRIMARY KEY, mycol TEXT ) ;
The exception is caused when I try to read the elements on the table with these 2 commands executed sequentially:
A) DELETE FROM mytable WHERE mycol IS NULL OR trim(mycol) = '' ;
B) SELECT mycol FROM mytable ORDER BY _id DESC ;
And then the crash is on the line:
string myColValue = rs.GetString(0);
With the following exception/stacktrace:
InvalidCastException: Specified cast is not valid.
Mono.Data.Sqlite.SqliteDataReader.VerifyType (System.Int32 i, System.Data.DbType typ)
Mono.Data.Sqlite.SqliteDataReader.GetString (System.Int32 i)
Note that the command "A" above is already my attempt at "fixing" the problem, but it is still crashing.
I dont know what else to try - what kind of data would cause that exception? If it was null, the "A" command would avoid it, and if it was any other kind of data it could be cast into string without a problem.
Any ideas?
One relevant info is that the SQLite driver/dll I was using until recently was VERY OLD (from ~2013), so maybe those players getting the crash are old players in which the database and/or table in question was created with this older DLL, and maybe the DB format isn't well supported anymore? If so, any suggestions on how could I detect this so I can drop/recreate the table?
Thanks
sqlite sqlite3
sqlite sqlite3
edited Nov 19 '18 at 19:51
rtzpe
asked Nov 19 '18 at 19:39
rtzpertzpe
180211
180211
Is the DELETE failing because of Referential Integrity? Could you add the WHERE to B and use one query instead of two? Is it possible the query is not returning any rows? Context free comment :)
– DinoCoderSaurus
Nov 21 '18 at 14:21
add a comment |
Is the DELETE failing because of Referential Integrity? Could you add the WHERE to B and use one query instead of two? Is it possible the query is not returning any rows? Context free comment :)
– DinoCoderSaurus
Nov 21 '18 at 14:21
Is the DELETE failing because of Referential Integrity? Could you add the WHERE to B and use one query instead of two? Is it possible the query is not returning any rows? Context free comment :)
– DinoCoderSaurus
Nov 21 '18 at 14:21
Is the DELETE failing because of Referential Integrity? Could you add the WHERE to B and use one query instead of two? Is it possible the query is not returning any rows? Context free comment :)
– DinoCoderSaurus
Nov 21 '18 at 14:21
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53381515%2fsqlite-getstring-specified-cast-is-not-valid%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53381515%2fsqlite-getstring-specified-cast-is-not-valid%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Is the DELETE failing because of Referential Integrity? Could you add the WHERE to B and use one query instead of two? Is it possible the query is not returning any rows? Context free comment :)
– DinoCoderSaurus
Nov 21 '18 at 14:21