Sqlite pending operation occuring while fetching data from database - sqlite

My code is:
Statement mstatement = null;
URI uri = URI.create(DBPath);
sqliteDb = DatabaseFactory.openOrCreate(uri);
mStatement = sqliteDb.createStatement(strQuery);
mStatement.prepare();
My problem is, I am getting error as "Sqlite pendingOperation" at mstatement.prepare();. Please tell me why I am getting this and how to remove it. One more thing, I am using this code in multiple threads.

Related

Why does this query crash if there are no matching results instead of returning an empty result?

I am using this query to get some statistics from our DB
SELECT DateTimePart("yyyy", c.RedeemedDate) AS RedeemedInYear,
DateTimePart("m", c.RedeemedDate) AS RedeemedInMonth,
AVG(c.RedPriceStoreSummary ?? c.WhitePriceStoreSummary) AS AverageBasketValue
FROM c
WHERE c.IsRedeemed = true
AND c.Brand = 'xxx'
AND c.RedeemedDate != null
AND DateTimePart("yyyy", c.RedeemedDate) = DateTimePart("yyyy", GetCurrentDateTime())
GROUP BY DateTimePart("m", c.RedeemedDate),
DateTimePart("yyyy", c.RedeemedDate)
The problem is that query crashes with the following error if there are no results
Cannot read property 'create' of undefined
If I force the query to where it gets results then everything works fine but I dont want the query to crash if there are no results I want an empty result set.
Am I missing something here?
You need to trap queries in a try block and catch if it returns a 404. This is a hold over in behavior from the previous SDK. Alternatively you can use the stream variant of these SDK functions which will not throw exceptions when data is not found, however you still want to check the http response code and you'll also need to manually deserialize the data.

Room unexpected behavior when working with BLOB & TEXT

I am migrating my app's SQLite helper to Room. Basically what I am doing is just copying data from old SQLite database to Room, so due to schema mismatch I need to provide migration. I am having this issue with BLOB data in Room.
I have below simple model
class NewCourse {
var weekday: Array<String> = arrayOf()
}
I also have TypeConverter as
#TypeConverter
fun toArray(concatenatedStrings: String?): Array<String>? {
return concatenatedStrings?.split(",".toRegex())?.dropLastWhile { it.isEmpty() }?.toTypedArray()
}
#TypeConverter
fun fromArray(strings: Array<String>?): String? {
return strings?.joinToString(",")
}
Within my old appdatabase.db database I have a corresponding table Course with a field weekday which has a type BLOB.
Well, because of my TypeConverter in room database I will have weekday with a type TEXT. While migrating I running below SQL script.
INSERT INTO NewCourse (weekday) SELECT weekday FROM Course
As weekday from Course table is BLOB type and in SQL you can basically store anything to anything, am I expecting it will copy BLOB-typed weekday in Course to TEXT-typed weekday in NewCourse.
Well at first I was expecting some error due to type mismatch. But "fortunately", but not expectedly, Room doesn't throw any exception and it gets value of BLOB and copies as TEXT.
My first question was why it is working? i.e. how it's copying the TEXT value of BLOB to my newly created table?
I never cared about it, as it was working perfectly, until I did some testing with Robolectic.
Unfortunately, I am getting error if I start testing with Robolectic. After copying data in my migration, when I query for NewCourse I am getting SQL error of
android.database.sqlite.SQLiteException: Getting string when column is blob. Row 0, col 10
So, I suppose here it is copying the data as BLOB and when querying for weekday it is throwing an exception as getWeekDay calls getString of cursor.
My second question would be "Why while testing with Robolectic it is not working as it is working with just running the app?"
I also tested the queries with just Sql not involving Android, and over there it copies the BLOB as BLOB even though the type of weekday at NewCourse is TEXT as expected.
Robolectric is a testing library for android applications. The keyword here is testing and by that it means there shouldn't be any exception. Robolectric showing you error maybe because of some android devices may throw exception so your application will crash. Try checking your logs while your application running. Maybe you are missing some warnings.

Perl dancer error execute method undefined

I was trying to make a website using perl dancer, below is my code. It seems to be correct but the page keeps loading and never enters the values in the database. When I cancel the page I get an error stating "request to POST /appform crashed: Can't call method "execute" on an undefined value". I can't figured out whats wrong in the code. If you have any other code please mention.
I am using SQLite for database.
There is a database campus.dband I am inserting the value in student table.
post '/appform' => sub {
my $q = CGI ->new;
my $name = $q->param ("firstname");
my $password = $q->param("password");
my $mobile_no = $q->param("mobile");
my $gender = $q->param("gender");
my $email = $q->param("email");
my $address = $q->param("address");
my $sslc = $q->param("SSLC");
my $hsc = $q->param("HSC");
my $cgpa = $q->param("cgpa");
my $languages = $q->param("lang");
my $internships = $q->param("intern");
my $preferred_loc = $q->param("country");
my $sql = "insert into student(name,mobile_no,gender,email,address,sslc,hsc,cgpa,languages,internships,preferred_loc,password,applied_job,company_applied) values ('?','?','?','?','?','?','?','?','?','?','?','?','?','?');";
my $sth = database->prepare($sql);
$sth->execute($name,$mobile_no,$gender,$email,$address,$sslc,$hsc,$cgpa,$languages,$internships,$preferred_loc,$password) or die $sth->errstr;
#$sth->execute();
$sth-> finish;
set_flash('New entry posted!');
redirect '/';
};
You're using the database keyword to get a database handle. I'm guessing that's coming from Dancer2::Plugin::Database (it would be useful if you could include information like this in your question).
The error says that you're calling execute() on an undefined value. You're calling execute() on the variable $sth. So $sth is undefined. You get $sth by calling prepare() on the database handle returned from database(). So it looks like the prepare() call is failing. You should check the return value from that call and throw an error if it fails.
The most common reason for prepare() to fail is that you're trying to compile an SQL statement that contains an error. I can't see any obvious error in your SQL, but it's worth checking it by running it manually against your database.
I see you're using bind params in your SQL statement. That's a great idea, but please note that you don't need to quote the question marks in your SQL - the database driver will handle that for you. I don't think that's what is causing your problem though.
I also see that you're using CGI.pm inside your Dancer app to get the request parameters. To be honest, I'm slightly surprised that it works - but it's a terrible idea. Dancer has its own keywords that will give you this information. Look at query_parameters(), body_parameters() and route_parameters() in the Dancer documentation.
In addition to the points made already, that your DBI prepare() call is probably failing (add error-checking to see why, e.g. my $sth = database->prepare('...') or die "DB error: " . database->errstr) and that you're using CGI.pm within a Dancer app (... don't do that, I'm surprised it would work at all - look at the Dancer documentation for how to access the params your app was sent), look also at the quick_insert convenience method provided by Dancer::Plugin::Database / Dancer2::Plugin::Database so that you don't have to write that SQL INSERT statement at all.

libgit2sharp.Patch outofmemory

I try to use libgit2sharp.Patch to find how much line added or deleted, but i got an error while i try to run it. When i run my asp.net mvc project in debug mode, it doesn't have any problem, until i run it without debug mode, i got my web load too long and didn't show the page. When i run in debug mode again, finally an error appear from libgit2sharp.Patch variable with error message system.outofmemory. This is how i implement libgit2sharp.Patch
Patch treePatchInfo = repo.Diff.Compare<Patch>(firstTree, compareTree, null, compareOptions: compareOptions);
commitChangeValue = from s in treeChangeInfo
let patch = treePatchInfo[s.Path]
select new CommitChangeModel
{
ChangeKind = s.Status,
LinesAdded = patch.LinesAdded,
LinesDeleted = patch.LinesDeleted,
OldPath = s.Path,
Patch = patch.Patch,
Path = s.Path
};
If you're only interested in number of additions/removal per file, I'd suggest you to rather rely on the following construct would be more efficient.
var stats = repo.Diff.Compare<PatchStats>(...);
You can take a peek at PR #660 where it's been introduced to get a first grasp of its usage.
Note: Regarding the OOM Exception, we'd very interested in getting more information about it. Would you be so kind as to open an issue in the bug tracker so that we can get a deeper look at it?

Reading Patient Name tag in DICOMDIR using clearcanvas in c#

I am new to CC as well as DICOM world, am trying out to read the patient name and study details in the DICOMDIR file and save it in database, here is my code, am doing it in console application in C#
enter code here
{
DicomDirectory reader = new DicomDirectory("DICOMDIR");
reader.Load(#"D:\Sunil\Dataset\Metapex\pix\DICOMDIR");
DirectoryRecordSequenceItem record = reader.RootDirectoryRecord;
while (record != null)
{
String PatientId = record[DicomTags.PatientId];
String PatientName = record[DicomTags.PatientsName];
Console.WriteLine("Id - {0}\n Name - {1}", PatientId, PatientName);
record = record.NextDirectoryRecord;
}
Console.ReadLine();}
when i execute it there is no error, but DirectoryRecordSequenceItem "record" value is returning null in line 3, hence it is not entering the loop.
can anyone help why it is returning null value, am not able to find out even i put breakpoint n debug it.
thanks in advance
SUNIL
This is the correct way to access the patient level directory records within a DICOMDIR. The code should work. Are you sure DICOMDIR itself is encoded properly?
You should be able to call reader.Dump() and investigate the directory record sequence to see if there are proper directory records there and they've been parsed. It would be difficult to confirm that the the actual points in the directory record are correct, but you should at least be able to see if there are records present.

Resources