GDX-SQLite android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1 - sqlite

I work in Android Studio with libgdx and gdx-sqlite. I want a simple query from my database with the following code.
try {
cursorSettings = dbHandler.rawQuery("SELECT "+COLUMN_SETTING+" FROM "+TABLE_SETTINGS+" WHERE "+COLUMN_SETTINGSID+" =13");
System.out.println(cursorSettings.getLong(0));
} catch (SQLiteGdxException e) {
e.printStackTrace();
}
The Desktop-Version works without problems, but in the android version I get the following error:
05-25 10:21:47.341 11978-12232/ch.shuttering.rapporte E/AndroidRuntime: FATAL EXCEPTION: GLThread 82275
Process: ch.shuttering.rapporte, PID: 11978
android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
at android.database.AbstractCursor.checkPosition(AbstractCursor.java:460)
at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:74)
at com.badlogic.gdx.sqlite.android.AndroidCursor.getLong(AndroidCursor.java:61)
at ch.shuttering.rapporte.Manager.SQLiteManager.SaveMangerSQLite.creatSQLiteSettings(SaveMangerSQLite.java:295)
at ch.shuttering.rapporte.RapporteMain.create(RapporteMain.java:66)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:311)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1546)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1262)
So every time I make a getXXX () query from the cursor I get an error, but if I now use the following code:
try {
cursorSettings = dbHandler.rawQuery("SELECT * FROM "+TABLE_SETTINGS);
} catch (SQLiteGdxException e) {
e.printStackTrace();
}
while (cursorSettings.next()) {
Gdx.app.log("FromDb", String.valueOf(cursorSettings.getString(1)));
}
I have a correct output with all data.
Does anyone have an idea what the problem is?
Thank you for your help

Okay I found the problem by myself, that was the code in the Android class
#Override
public long getLong (int columnIndex) {
try {
return cursor.getLong(columnIndex);
} catch (SQLiteException e) {
Gdx.app.log(DatabaseFactory.ERROR_TAG, "There was an error in getting the long", e);
throw new SQLiteGdxRuntimeException(e);
}
}
The problem is that in android the cursor points to -1 so it must first be set to the correct position, the following code solves the problem
#Override
public long getLong (int columnIndex) {
try {
cursor.moveToFirst();
return cursor.getLong(columnIndex);
} catch (SQLiteException e) {
Gdx.app.log(DatabaseFactory.ERROR_TAG, "There was an error in getting the long", e);
throw new SQLiteGdxRuntimeException(e);
}
}
You can found this code in the library gdx-sqlite-android.jar in the class AndroidCursor.
I hope the solution helps someone.

Related

Xamarin, SQLite : Don't know how to read System.Char

I use the below code to search SQLite table. It works fine with Android 9. But I receive the below error in Android 10.
Where should I check or how can I make minimal change in the code so that it will work on Android 10 also.
Edit 1:
I'm using the following versions.
Xamarin.Forms v4.5.0.495
Xamarin.Essentials v1.3.1
sqlite-net-pcl v1.7.335
Code:
public SearchPage()
{
InitializeComponent();
conn = DependencyService.Get<ISQLiteMyConnection>().GetConnection();
try
{
DisplayLines("");
}
catch (Exception ex)
{
DisplayAlert("Error", ex.Message, "Ok");
}
}
public void DisplayLines(string searchText)
{
if (String.IsNullOrWhiteSpace(searchText))
{
var details = (from x in conn.Table<QLines>() select x).ToList();
myLines.ItemsSource = details;
searchCount.Text = "";
}
else
{
var details1 = (from x in conn.Table<QLines>() where x.PartA.Contains(searchText) || x.PartB.Contains(searchText) select x).ToList();
myLines.ItemsSource = details1;
searchCount.Text = "Matches found : " + details1.Count.ToString();
}
}
private void SearchBar_TextChanged(object sender, TextChangedEventArgs e)
{
DisplayLines(e.NewTextValue);
}
Error:
Don't know how to read System.Char
I got the issue.
The nuget package SQLite.Net.Core-PCL is deprecated. This package is handling LINQ like query on SQLite db. Suggested alternative is sqlite-net-pcl. Might be, I need to revise the code.
Edit: I have updated the Xamarin Form to version 5. And revised the code ( I used query instead of LINQ)

Calling function itselft within exception

Hı,
I try to create a code that when catch an exception call itself one more time but with different argument. Recursion sample is below.
It is working fine it work for first way if it catch exception call with second way; if it has exception for second way return false, but I want to ask wheter it is a good coding or junk?
public void Main(){
console.log(testing(true));
}
private boolean testing(boolean isFirstWay)
{
try{
if(isFirstWay){
// set something, call some functions for first way
return true;
} else{
// set something, call some functions for second way
return true;
}
} catch(Exception e)
{
if(isFirstWay){
return testing(false);
} else {
return false;
}
}
}

Message Stucks (Microsoft.Samples.BizTalk.Adapter.Common )

We use Microsoft.Samples.BizTalk.Adapter.Common library for our custom SMTP Receive Adapter. Everything seems fine except one situation. The message stucks if it larger than approximatly 5 MB and it includes more than two attachments. Our adapter is run on isoletadHost. In query window we see that the message stay in active status. During our investigation we found that it stucks in a batch.Wait() method. Any other messages handling well. We are running Biztalk 2006 Standart.
Could anyone provide us with any suggestion?
SyncReceiveSubmitBatch batch = new SyncReceiveSubmitBatch(transportProxy, terminator, 1);
Int32 count = 0;
foreach (IBaseMessage msg in messages)
{
try
{
batch.SubmitMessage(msg, null);
count++;
}
catch (Exception ex)
{
try
{
msg.SetErrorInfo(ex);
batch.MoveToSuspendQ(msg);
ThreadContext.Properties["EventID"] = 1007;
logger.Error("Submit Error", ex);
}
catch (Exception ex2)
{
ThreadContext.Properties["EventID"] = 1008;
logger.Error("Suspend Error", ex2);
}
}
}
if (count != 0)
{
batch.Done();
if (batch.Wait())
{
ThreadContext.Properties["EventID"] = 1009;
logger.Debug("Messages publised");
}
else
{
ThreadContext.Properties["EventID"] = 1010;
logger.Warn(String.Format("Publish error. Sucssefully publised {1}, error in {0} messages", batch.FailedMessages.Count, count - batch.FailedMessages.Count));
}
}
else
{
ThreadContext.Properties["EventID"] = 1011;
logger.Warn("No message found");
}
This fix: http://support.microsoft.com/kb/928078 helped to solve the problem. Thanks all.

Need help inresilving the bug

How can i Remove this error. pls Help me in this...
Error 1 Cannot implicitly convert type 'System.Collections.Generic.List<Linq.Model.usp_DisplayrecordsResult>' to 'System.Data.Linq.Link<Linq.Model.usp_DisplayrecordsResult>' C:\Users\anu\Documents\Visual Studio 2010\Projects\Linq.DAL\DAL.cs 23 24 Linq.DAL
method in which error raised is as follows..
Linq.Model.DataAccessDataContext _DataAccessDataContext;
public Link<usp_DisplayrecordsResult> DispPersons()
{
try
{
_DataAccessDataContext = new Linq.Model.DataAccessDataContext();
var query = _DataAccessDataContext.usp_Displayrecords();
List<usp_DisplayrecordsResult> Listresult = new List<usp_DisplayrecordsResult>(query);
return Listresult;
}
catch (Exception ex)
{
throw ex;
}
}
I don't think that you intended to use the Link structure as return type. If you change that to List it will compile:
public List<usp_DisplayrecordsResult> DispPersons()

How to enable create / insert in a AxGridView in Enterprise Portal (Dynamics AX 2009)

There must be a way to enable creation and insertion of a record from a AxGridView without using the Tunnel and Wizard approach. From what I have found on the Internet so far, the only example is using a Wizard, and I honestly don't find that to be a user friendly approach.
Has anyone tried to enable insertion of records directly from a AxGridView?
Yes it is possible to enter data through AxGridView. Just enable Editing, deleting for that control. And one more thing to make new row - you have to make addditional button - create new line, and code behind:
protected void NewLine_Click(object sender, EventArgs e)
{
int editIdx = AxGridView1.EditIndex;
try
{
// Save the last unsaved line if any
if (AxGridView1.EditIndex != -1 && AxGridView1.Rows.Count > 0)
{
this.AxGridView1.UpdateRow(AxGridView1.EditIndex, true);
}
DataSetViewRow dsvr = this.dsv.AddNew();
}
catch (System.Exception ex)
{
AxExceptionCategory exceptionCategory;
if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))
{
// Throw the fatal exception
throw;
}
if (exceptionCategory == AxExceptionCategory.NonFatal)
{
AxGridView1.EditIndex = editIdx;
}
}
}
private DataSetView dsv //get dataset view
{
get
{
DataSet dataSet = this.AxDataSource1.GetDataSet();
return dataSet.DataSetViews[this.AxGridView1.DataMember];
}
}

Resources