Skip to content
.NET Standard SQLite Wrapper for all platforms. Including: .NET, iOS, Android, UWP. No platform specific libraries
Branch: master
Clone or download
Pull request Compare This branch is 127 commits ahead, 1 commit behind oysteinkrog:master.

README.mdown

Pure .NET Standard C# SQLite Wrapper

Purpose / Features

Provide a .NET Standard library that sits across the four main platforms: UWP, Android, .NET and iOS with no platform specific libraries.

Provide flat table access with SQL queries. I.e. not being forced to use language integrated ORM like functionality.

Pull requests welcome! Any attempts to address the existing issues are welcome.

Quick Start

Simply clone the repo, open the solution in Visual Studio 2017, and run the sample apps. There are samples for .NET, Android, iOS, and UWP. They all compile and run. They have all been tested.

NuGet

Install-Package SQLite.Net.Standard

Example

Create Table:

        Execute(
        "CREATE TABLE VALUATION( " +
        "    ID STRING PRIMARY KEY     NOT NULL, " +
        "    STOCKID           INT NOT NULL, " +
        "    Price           TEXT NOT NULL " +
       ");");   

Insert

        Execute("INSERT INTO VALUATION (ID, STOCKID, Price) VALUES(@Param1, @Param2, @Param3);", new object[] { Guid.NewGuid().ToString(), valuation.StockId, valuation.Price });

Read From Table

    public SQLiteCommandResult GetData()
    {
        var command = CreateCommand("SELECT * FROM 'VALUATION'");
        var data = command.ExecuteDeferredQuery();

        return data;
    }

Create SQLiteCommand Command

Note: This is not a complete, self inclusive example. You need to read between the lines here. This is an example of how to return a flat table of data in the SQLiteCommandResult structure. It used the ExecuteDeferredQuery method which is my main addition to the original repo.

    private SQLiteCommand CreateCommand(string commandText, IList<DataParameter> parameters)
    {
        var command = _Connection.CreateCommand(commandText);

        if (parameters == null)
        {
            return command;
        }

        for (var i = 0; i < parameters.Count; i++)
        {
            if (parameters[i].ParameterValue is DateTime dateTimeValue)
            {
                var dateText = dateTimeValue.ToString(_ISOStandardDate);
                parameters[i] = new DataParameter(parameters[i].ParameterName, dateText);
            }

            command.Bind(parameters[i].ParameterName, parameters[i].ParameterValue);
        }

        return command;
    }


    private SQLiteCommandResult GetData(string commandText, IList<DataParameter> parameters, TableInfo tableInfo)
    {
        var command = CreateCommand(commandText, parameters);
        var commandResult = command.ExecuteDeferredQuery();

        if (tableInfo == null)
        {
            return commandResult;
        }

        foreach (var column in tableInfo.ColumnsByName)
        {
            foreach (var row in commandResult.Data)
            {
                if (!row.ContainsKey(column.Key))
                {
                    continue;
                }

                var theValue = row[column.Key];
                row[column.Key] = SQLiteDataTypeConvert(theValue, column.Value.PropertyInformation.PropertyType);
            }
        }

        return commandResult;
    }

Forked From

https://github.com/oysteinkrog/SQLite.Net-PCL

Please follow the forks backward for earlier forks.

You can’t perform that action at this time.