gnux8
Posts: 11
Joined: Fri Aug 14, 2015 9:10 am

SQL LITE very slow

Thu Jan 12, 2017 12:46 pm

Good Afternoon,

do you know why sql lite is performing very slow on raspberry ?

for update a row bring about 3 seconds too much,

thanks in advance for the support,

br
Andrea

scotty101
Posts: 3958
Joined: Fri Jun 08, 2012 6:03 pm

Re: SQL LITE very slow

Thu Jan 12, 2017 1:54 pm

Can you share your code?

You might be doing something incorrectly.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

gnux8
Posts: 11
Joined: Fri Aug 14, 2015 9:10 am

Re: SQL LITE very slow

Thu Jan 12, 2017 3:17 pm

yes sure sorry,

Code: Select all

using SQLite.Net.Attributes;

namespace Audio
{
    /// <summary>
    /// In questo punto si struttura il Database che sarà inviato a raspberry
    /// </summary>
    public class Contabilita

    {
        [PrimaryKey, AutoIncrement]
        public int Id { get; set; }
        public float NumberOfCredit { get; set; }    // Numero di crediti dopo inserimento moneta
        public float NumberOfMatches { get; set; }   // Numero di partite Totali giocate
        public float NumberOfTotalCoin { get; set;}  // Numero Totale di Crediti 
        public float NumberOfWinMatches { get; set; }  // Numero Totale di Partite Vinte 
    }


Code: Select all

        string path;
        SQLite.Net.SQLiteConnection conn;
CONNECT TO DB

Code: Select all

 public void ConnectToDatabase()
        {
            path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite");
            //path = Path.Combine("C:\\DB", "db.sqlite");


            //using (var conn = new SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path))
            //{
            //    conn.CreateTable<Contabilita>();
            //    conn.RunInTransaction(() =>
            //    {
            //        conn.Insert(new Contabilita()
            //        {
            //            NumberOfCredit = 1,
            //            NumberOfMatches = 0,
            //            NumberOfTotalCoin = 0,
            //            NumberOfWinMatches = 0

            //        });
            //    });
            //}

            conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path);
            //conn.DeleteAll<Contabilita>();
            //conn.CreateTable<Contabilita>();
            //conn.Insert(new Contabilita()
            //{
            //    NumberOfCredit = 1,
            //    NumberOfMatches = 0,
            //    NumberOfTotalCoin = 0,
            //    NumberOfWinMatches = 0

            //});

           // conn.Commit();

        }
READ DB

Code: Select all

        public void ReadContabilita(ref float NumeroCrediti, ref float NumeroPartite, ref float NumerodiMonete, ref float NumeroPartiteVinte)
        {
            var tmp = conn.Table<Contabilita>().FirstOrDefault();
            NumeroCrediti = tmp.NumberOfCredit;
            NumeroPartite = tmp.NumberOfMatches;
            NumerodiMonete = tmp.NumberOfTotalCoin;
            NumeroPartiteVinte = tmp.NumberOfWinMatches;
        }

UPDATE DB

Code: Select all

public void UpdateContabilita(float NumeroCrediti, float NumeroPartite, float NumerodiMonete, float NumeroPartiteVinte)
        {
           // var tmp = conn.Table<Contabilita>().FirstOrDefault(c => c.Id == 0);
            var tmp = conn.Table<Contabilita>().FirstOrDefault();
            tmp.NumberOfCredit = NumeroCrediti;
            tmp.NumberOfMatches = NumeroPartite;
            tmp.NumberOfTotalCoin = NumerodiMonete;
            tmp.NumberOfWinMatches = NumeroPartiteVinte;
           
            conn.Update(tmp);
            conn.Commit();
        }
it's only a row

thanks you very much,

br
Andrea

skipfire
Posts: 29
Joined: Fri Dec 30, 2016 1:27 pm
Location: Indiana, USA

Re: SQL LITE very slow

Sat Jan 14, 2017 1:14 am

How is the performance of your SD card?

gnux8
Posts: 11
Joined: Fri Aug 14, 2015 9:10 am

Re: SQL LITE very slow

Mon Jan 16, 2017 7:06 am

CLASS 10 10MB/s

Return to “Windows 10 for IoT”