SQLite.NET PCL Documentation?

NPCNPC USMember ✭✭

I've been trying to use SQLite in my application. However I find it difficult to find any helpful resources on the subject. For instance I'd like to prevent creating multiples of the same table in the database, but I can't find anything that lists out the methods and defines them to see if you even can create duplicate tables and/or if writes over the existing one. Yes I know it has it's own little wiki on the GitHub page, but it doesn't seem to have anything helpful beyond basic syntax. Even that itself doesn't explain how it parses it's string parameter for Query.

I was wondering if any of you devs have any good references for this?

Answers

  • JohnMillerJohnMiller USForum Administrator, Xamarin Team Xamurai

    @NPC,

    Are you referring to this SQLite library? The GitHub page is the only documentation I know of. To address your concern, the CreateTable<T> method only creates a new table if it does not exist. If the schema changed in the model used for the Table, and it already exists, it attempts to migrate it. You can see all of this here. Hope that helps!

  • NPCNPC USMember ✭✭

    Thank you for responding. Do you know any guides that show how to run SQLiteCommands? I would prefer if I could just run a string of SQL command such as "CREATE DATABASE IF NOT EXISTS xxx". However it seems that the SQLiteCommand object has no public constructors as VS claims it has not 0,1,2,3, or 4 argument constructors. Could you review this and tell me where I'm going wrong?

    I have a class named Database in which it has an SQLiteAyncConnection member named data.

    public Database( string path ){
    var database = new SQLiteAsyncConnection(path);
    database.CreateTableAsync();
    data = database;
    }

    public void updateUser(String id, String cred)
    {
    User update = new User { curID = id, credentials = cred };
    data.InsertOrReplaceAsync(update);
    }

    public string getUserId()
    {
    Task<List> task = getID();
    List user = task.Result;
    return user[0].curID;
    }

    private async Task<List> getID()
    {
    return await data.QueryAsync("SELECT * FROM User");
    }

  • Tech_AdamTech_Adam Member
    edited July 2018

    If you're looking for a tutorial on SQlite then tutorialspoint.com has one.

Sign In or Register to comment.