5

I have a problem with the reading of the tables on the SQLite database.

my OBJ_User class:

    namespace Fimap.Models
{
    public class OBJ_User
    {
        public int DLR_Id { get; set; }
        public string DLR_Username { get; set; }
        public string DLR_Password_Hash { get; set; }
        public object DLR_Nome { get; set; }
        public string DLR_Cognome { get; set; }
        public int DLR_Tipo { get; set; }
        public string DLR_Azienda { get; set; }
        public object DLR_Telefono { get; set; }
        public object DLR_Email { get; set; }
        public int DLR_Abilitato { get; set; }
        public object DLR_Time_Zone { get; set; }
        public object DLR_Country { get; set; }
        public string DLR_Culture { get; set; }
        public object DLR_Email1 { get; set; }
        public object DLR_MCC_Modello_Alias { get; set; }
        public object DLR_Anagrafica { get; set; }
        public object DLR_Firma { get; set; }
        public bool IsFIMAP { get; set; }
        public bool IsSTANDARD { get; set; }
        public bool IsDealerOrFimap { get; set; } //true dealer - false user
        public object DLR_Tipo_Esteso { get; set; }
        public object DLR_Abilitato_Esteso { get; set; }
    }
}

my interface in pcl project:

public interface IDatabaseConnection
    {
        SQLite.SQLiteConnection DbConnection();
    }

Android

[assembly: Xamarin.Forms.Dependency(typeof(DatabaseConnection_Android))]
namespace Fimap.Droid
{
    public class DatabaseConnection_Android : IDatabaseConnection
    {
        public SQLiteConnection DbConnection()
        {
            var dbName = "FimapDB.db3";
            var path = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), dbName);
            return new SQLiteConnection(path);
        }
    }
}

iOS

[assembly: Xamarin.Forms.Dependency(typeof(DatabaseConnection_iOS))]
namespace App.iOS
{
    public class DatabaseConnection_iOS : IDatabaseConnection
    {
        public SQLiteConnection DbConnection()
        {
            var dbName = "FimapDB.db3";
            string personalFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            string libraryFolder = Path.Combine(personalFolder);
            var path = Path.Combine(libraryFolder, dbName);
            return new SQLiteConnection(path);
        }
    }
}

pcl connection (database is right connect):

database = DependencyService.Get<IDatabaseConnection>().DbConnection();

enter image description here

query:

var test = database.Query<OBJ_User>("SELECT * FROM OBJ_User");

when i launch the query i have this error:

SQLite.SQLiteException: no such table: OBJ_User

enter image description here

OBJ_User is in the dabatase with one record. Why the connection don't mapping the table ? database variable is right connect to database sqlite, i don't understand because database don't get mapping from sqlite file. Solution ?

if you want other info write me in the comment, i will answer

5
  • 1
    Do you call database.CreateTable<OBJ_User>(); anywhere in your code? I know that you already have the table in the database, but you may need to "Create" it for the SQLite library to get the mapping. Commented Feb 7, 2017 at 15:01
  • Also as a side note, parameterizing your query can be helpful to avoid making spelling mistakes (ie var test = database.Query<OBJ_User>("SELECT * FROM ?", nameof(OBJ_user)); The ? just gets filled in with the parameter and the library does some work internally to make sure it's formatted correctly. Commented Feb 7, 2017 at 15:04
  • if i do database.CreateTable<OBJ_User>(); i get this error: System.NotSupportedException: Don't know about System.Object, then if i do var test = database.Query<OBJ_User>("SELECT * FROM ?", nameof(OBJ_user)); i have the error on OBJ_User. Commented Feb 7, 2017 at 15:21
  • Can you add the code for your OBJ_User class declaration? I think this has something to do with having a List of non CLR type in your class declaration which is not supported by the library. link Commented Feb 7, 2017 at 15:49
  • i added the class, do you think that is wrong class ? Commented Feb 7, 2017 at 15:53

1 Answer 1

6

The SQLite library doesn't know how to map the properties of type object to a sqlite column. The SQLite library supports the following column types by default: string, int, double, byte[], DateTime.

Sign up to request clarification or add additional context in comments.

5 Comments

i have tried to remove element with type "object", i have left only string and int object..that works.! Thanks. I sign right answer.
The last question, if we do not do "database.CreateTable <OBJ_User> ();" the table is not created, you can use an existing database? since I have one with about 1000 records.
The problem remains, does the mapping, while if I table creation works, but I'm going to lose existing records if I create a table.
CreateTable will not drop any records that you have in your database. It simply creates a table if it does not exist and adds that mapping to the connection. Is that what you are asking?
exatly i have tried after your response, thank you so much. good works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.