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

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)

Related

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

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.

Local SQLite DB in FLex Mobile app

I'm coding an app for Android and iOS devices using Flex. I've an SQLite db already created and I want access to his data. I've seen some code looking with google but I'm not able to run nothing.
I would appreciate if you can explain me where I've to put the file.db into my project and if you share me some simple code that allow to connect to file.db and select some rows.
Sorry for my bad english and thanks in advance.
The code bellow will return an object with the data from the database.
package bd
{
public class SQLPadConnection extends SQLStatement
{
protected var _DBFilePatch:String = "DB.sqlite";
protected var _conn:SQLConnection = new SQLConnection();
public function SQLPadConnection()
{
var folder:File = File.userDirectory.resolvePath('com.app.directoryName');
if (!folder.exists) {
folder.createDirectory();
}
_conn.open(folder.resolvePath(_DBFilePatch));
this.sqlConnection = _conn;
super();
}
public function getSQLData(SQL:String = ""):Object
{
if (StringUtil.trim(SQL) != "")
{
this.begin();
this.text = SQL;
this.execute();
this.commit();
return this.getResult();
}
else
return null;
}
}
}
To use that, just do like bellow:
var res:Object = new Object();
var SQL:SQLPadConnection = new SQLPadConnection();
res = SQL.getSQLData("SELECT * FROM TABLE");
res = SQL.getSQLData("INSERT INTO/ UPDATE/ DELETE...");
Hope this help someone.
I'm going to assume you actually meant AIR, this runtime is what allows you to connect to SQLite. In which case there is gobs of information just in the reference alone...
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/data/SQLConnection.html

How to use plsql-parser (ANTLR)

I'd like to check PL/SQL query syntax in automated tests, and it looks like https://github.com/porcelli/plsql-parser might be useful for that. I am not easily finding out how I would install and use it though.
Note that this is for a Ruby project, but I'm reasonably competent in Java. I'm hoping there's some way I can run the checking via console, pass in the SQL, and get back any error info, including line/column.
Thanks.
Download the ANTLR tool ver 3.5.1
Download the source codes from here (as this version was ported to 3.5.1)
Use the tool to compile the sources from poarsers/no-ast subdir
1st compile PLSQLLexer.g
2nd compile PLSQLParser.g from no-ast subdir
the use this sample code as an example:
import org.antlr.runtime.ANTLRNoCaseFileStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import br.com.porcelli.parser.plsql.PLSQLLexer;
import br.com.porcelli.parser.plsql.PLSQLParser;
public static void parse(String file) {
try {
PLSQLLexer lex = new PLSQLLexer(new ANTLRNoCaseFileStream(file));
CommonTokenStream tokens = new CommonTokenStream(lex);
PLSQLParser parser = new PLSQLParser(tokens);
/*start_rule_return AST =*/ parser.data_manipulation_language_statements();
System.err.println(file +": " + parser.getNumberOfSyntaxErrors());
if(parser.getNumberOfSyntaxErrors() != 0)
{
//System.exit(1);
}
} catch (RecognitionException e) {
System.err.println(e.toString());
} catch (IOException e) {
System.err.println(e.toString());
} catch (java.lang.OutOfMemoryError e) {
System.err.println(file + ":");
System.err.println(e.toString());
} catch (java.lang.ArrayIndexOutOfBoundsException e) {
System.err.println(file + ":");
System.err.println(e.toString());
}
}

Setting default TWAIN data source without using API UI menu

Using the twaindotnet library in C#, I'm wondering if there's a way to set the default datasource using the library.
As a feeble attempt, I've tried adding a SetDefault method to the DataSource class of twaindonet, like this
public static void SetDefault(Identity applicationId, IWindowsMessageHook messageHook, DataSource newDataSource)
{
var defaultSourceId = newDataSource.SourceId;
// Attempt to get information about the system default source
var result = Twain32Native.DsmIdentity(
applicationId,
IntPtr.Zero,
DataGroup.Control,
DataArgumentType.Identity,
Message.Set,
defaultSourceId);
if (result != TwainResult.Success)
{
var status = DataSourceManager.GetConditionCode(applicationId, null);
throw new TwainException("Error getting information about the default source: " + result, result, status);
}
}
which is called from the DataSourceManage class like this
public void SelectSource(DataSource dataSource)
{
DataSource.Dispose();
DataSource.SetDefault(ApplicationId, _messageHook, dataSource);
}
But when I try to use SetDefault, Twain32Native.DsmIdentity always results in Failure being returned.
I basically copied from SetDefault the setDefaultDataSource method from TWAIN sample Data Source and Application
pTW_IDENTITY TwainApp::setDefaultDataSource(unsigned int _index)
{
if(m_DSMState < 3)
{
cout << "You need to open the DSM first." << endl;
return NULL;
}
else if(m_DSMState > 3)
{
PrintCMDMessage("A source has already been opened, please close it first\n");
return NULL;
}
if(_index >= 0 && _index < m_DataSources.size())
{
m_pDataSource = &(m_DataSources[_index]);
// set the specific data source
TW_UINT16 twrc;
twrc = _DSM_Entry(
&m_MyInfo,
0,
DG_CONTROL,
DAT_IDENTITY,
MSG_SET,
(TW_MEMREF) m_pDataSource);
switch (twrc)
{
case TWRC_SUCCESS:
break;
case TWRC_FAILURE:
printError(0, "Failed to get the data source info!");
break;
}
}
else
{
return NULL;
}
return m_pDataSource;
}
Any help would be greatly appreciated.
The possible cause is that the version of your TWAIN DSM is too low. Only DSM 2.0 or above supports setting default TWAIN data source.

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