Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions

Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions

Scheduled Pinned Locked Moved C#
databasequestionandroidmobilesqlite
52 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    Exoskeletor wrote:

    1. convert them with +s from all the images to one string,

    Not "all" the images; you need a separate fingerprint for each image.

    Exoskeletor wrote:

    i think i have to read the images as files, and in order to do that i have to open a stream, this sounds very heavy to me

    You'd have to read the images anyway to use them; opening them as a stream is not heavy, but the most used way to handle binary data. Since it is XML-data and not binary, you may get away with simply reading that string without needing a stream.

    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

    E Offline
    E Offline
    Exoskeletor
    wrote on last edited by
    #28

    but if i have a seperate hash for every image where im going to store it? in the templateimage table? one hash for each image?

    L 1 Reply Last reply
    0
    • E Exoskeletor

      but if i have a seperate hash for every image where im going to store it? in the templateimage table? one hash for each image?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #29

      Exoskeletor wrote:

      one hash for each image?

      Yes; since each hash represents the content in the image, in another form. If you have that for each image, then looking if you already have it is as easy as getting the hash from the new image (the one you want to compare to the ones already there), and see if it is in there.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

      E 1 Reply Last reply
      0
      • L Lost User

        Exoskeletor wrote:

        one hash for each image?

        Yes; since each hash represents the content in the image, in another form. If you have that for each image, then looking if you already have it is as easy as getting the hash from the new image (the one you want to compare to the ones already there), and see if it is in there.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

        E Offline
        E Offline
        Exoskeletor
        wrote on last edited by
        #30

        yes but what if i don't mind if the same image exist but not in the same order? thats why im thinking of converting all bytes into one. A template might have some images that other template have (in the future). Since i am generating bitmaps for every image maybe is not so expensive to generate one more md5 from a bitmap that will do that

        public static byte[] ConcatByteArrays(params byte[][] arrays)
        {
        return arrays.SelectMany(x => x).ToArray();
        }

        and then have a hash for every template AND a hash for every image

        E 1 Reply Last reply
        0
        • E Exoskeletor

          yes but what if i don't mind if the same image exist but not in the same order? thats why im thinking of converting all bytes into one. A template might have some images that other template have (in the future). Since i am generating bitmaps for every image maybe is not so expensive to generate one more md5 from a bitmap that will do that

          public static byte[] ConcatByteArrays(params byte[][] arrays)
          {
          return arrays.SelectMany(x => x).ToArray();
          }

          and then have a hash for every template AND a hash for every image

          E Offline
          E Offline
          Exoskeletor
          wrote on last edited by
          #31

          I tried with this code but im getting an out of memory exception

          static class DatabaseHelper
          {
          public static string GetMD5Hash(string content)
          {
          using (var md5 = MD5.Create())
          {
          byte[] computedHash = md5.ComputeHash(Encoding.UTF8.GetBytes(content));
          return new System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary(computedHash).ToString();
          }
          }

              public static string GetMD5Hash(byte\[\] content)
              {
                  using (var md5 = MD5.Create())
                  {
                      byte\[\] computedHash = md5.ComputeHash(Encoding.UTF8.GetBytes(BitConverter.ToString(content).Replace("-", "")));
                      return new System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary(computedHash).ToString();
                  }
              }
              public static string DrawableToMD5(int drawableId)
              {
                  var templateDB = new TemplateDB();
                  return GetMD5Hash(templateDB.DrawableToByteArray(drawableId));
              }
              private static SQLiteConnection instance;
              public static SQLiteConnection db()
              {
                  if (instance == null)
                      instance = new SQLiteConnection(System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "TemplatesData.db"));
          
                  return instance;
              }
              public static void CloseConnection()
              {
                  if (instance != null)
                  {
                      instance.Close();
                      instance.Dispose();
                      instance = null;
                  }
              }
          
          }
          public class TemplateDB
          {
              public enum TemplateCategories
              {
                  Emojis,
                  Stars,
                  Hearts,
                  Characters,
                  Emotions,
              }
          
              public static byte\[\] ConcatByteArrays(params byte\[\]\[\] arrays)
              {
                  return arrays.SelectMany(x => x).ToArray();
              }
          
              public static byte\[\] ConcatByteList(List list)
              {
                  return list
                      .SelectMany(a => a)
                      .ToArray();
              }
          
              public static Bitmap GetBitmapFromVectorDrawable(Context context, int drawableId)
              {
                  Drawable drawable = ContextCompat.GetDrawable(context, drawableId);
                  if (Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.Lollipop)
                  {
                      drawable = (DrawableCompat.Wrap(drawable)).Mutate();
          
          E L 2 Replies Last reply
          0
          • E Exoskeletor

            I tried with this code but im getting an out of memory exception

            static class DatabaseHelper
            {
            public static string GetMD5Hash(string content)
            {
            using (var md5 = MD5.Create())
            {
            byte[] computedHash = md5.ComputeHash(Encoding.UTF8.GetBytes(content));
            return new System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary(computedHash).ToString();
            }
            }

                public static string GetMD5Hash(byte\[\] content)
                {
                    using (var md5 = MD5.Create())
                    {
                        byte\[\] computedHash = md5.ComputeHash(Encoding.UTF8.GetBytes(BitConverter.ToString(content).Replace("-", "")));
                        return new System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary(computedHash).ToString();
                    }
                }
                public static string DrawableToMD5(int drawableId)
                {
                    var templateDB = new TemplateDB();
                    return GetMD5Hash(templateDB.DrawableToByteArray(drawableId));
                }
                private static SQLiteConnection instance;
                public static SQLiteConnection db()
                {
                    if (instance == null)
                        instance = new SQLiteConnection(System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "TemplatesData.db"));
            
                    return instance;
                }
                public static void CloseConnection()
                {
                    if (instance != null)
                    {
                        instance.Close();
                        instance.Dispose();
                        instance = null;
                    }
                }
            
            }
            public class TemplateDB
            {
                public enum TemplateCategories
                {
                    Emojis,
                    Stars,
                    Hearts,
                    Characters,
                    Emotions,
                }
            
                public static byte\[\] ConcatByteArrays(params byte\[\]\[\] arrays)
                {
                    return arrays.SelectMany(x => x).ToArray();
                }
            
                public static byte\[\] ConcatByteList(List list)
                {
                    return list
                        .SelectMany(a => a)
                        .ToArray();
                }
            
                public static Bitmap GetBitmapFromVectorDrawable(Context context, int drawableId)
                {
                    Drawable drawable = ContextCompat.GetDrawable(context, drawableId);
                    if (Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.Lollipop)
                    {
                        drawable = (DrawableCompat.Wrap(drawable)).Mutate();
            
            E Offline
            E Offline
            Exoskeletor
            wrote on last edited by
            #32

            What if i just give my own unique hash in every template manually? i cant think of another solution, either way im creating a list of templates before inserting them to db, why not just give them my own hash?

            L 1 Reply Last reply
            0
            • E Exoskeletor

              What if i just give my own unique hash in every template manually? i cant think of another solution, either way im creating a list of templates before inserting them to db, why not just give them my own hash?

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #33

              Exoskeletor wrote:

              What if i just give my own unique hash in every template manually? i cant think of another solution, either way im creating a list of templates before inserting them to db, why not just give them my own hash?

              You already assign them an id; if you want to compare if two complex objects are the same, you usually do that by comparing their hash values.

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

              E 1 Reply Last reply
              0
              • E Exoskeletor

                I tried with this code but im getting an out of memory exception

                static class DatabaseHelper
                {
                public static string GetMD5Hash(string content)
                {
                using (var md5 = MD5.Create())
                {
                byte[] computedHash = md5.ComputeHash(Encoding.UTF8.GetBytes(content));
                return new System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary(computedHash).ToString();
                }
                }

                    public static string GetMD5Hash(byte\[\] content)
                    {
                        using (var md5 = MD5.Create())
                        {
                            byte\[\] computedHash = md5.ComputeHash(Encoding.UTF8.GetBytes(BitConverter.ToString(content).Replace("-", "")));
                            return new System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary(computedHash).ToString();
                        }
                    }
                    public static string DrawableToMD5(int drawableId)
                    {
                        var templateDB = new TemplateDB();
                        return GetMD5Hash(templateDB.DrawableToByteArray(drawableId));
                    }
                    private static SQLiteConnection instance;
                    public static SQLiteConnection db()
                    {
                        if (instance == null)
                            instance = new SQLiteConnection(System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "TemplatesData.db"));
                
                        return instance;
                    }
                    public static void CloseConnection()
                    {
                        if (instance != null)
                        {
                            instance.Close();
                            instance.Dispose();
                            instance = null;
                        }
                    }
                
                }
                public class TemplateDB
                {
                    public enum TemplateCategories
                    {
                        Emojis,
                        Stars,
                        Hearts,
                        Characters,
                        Emotions,
                    }
                
                    public static byte\[\] ConcatByteArrays(params byte\[\]\[\] arrays)
                    {
                        return arrays.SelectMany(x => x).ToArray();
                    }
                
                    public static byte\[\] ConcatByteList(List list)
                    {
                        return list
                            .SelectMany(a => a)
                            .ToArray();
                    }
                
                    public static Bitmap GetBitmapFromVectorDrawable(Context context, int drawableId)
                    {
                        Drawable drawable = ContextCompat.GetDrawable(context, drawableId);
                        if (Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.Lollipop)
                        {
                            drawable = (DrawableCompat.Wrap(drawable)).Mutate();
                
                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #34

                That's reading all the images and making one big array of bytes of it; may be a bit much for the memorymanager.

                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                E 1 Reply Last reply
                0
                • L Lost User

                  Exoskeletor wrote:

                  What if i just give my own unique hash in every template manually? i cant think of another solution, either way im creating a list of templates before inserting them to db, why not just give them my own hash?

                  You already assign them an id; if you want to compare if two complex objects are the same, you usually do that by comparing their hash values.

                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                  E Offline
                  E Offline
                  Exoskeletor
                  wrote on last edited by
                  #35

                  well i cant seem to find a way to do that, i have also create this funny post in stackoverflow with that matter :) c# - Checking if data exist in sqlite-net before inserting them to database - Stack Overflow[^]

                  L 1 Reply Last reply
                  0
                  • E Exoskeletor

                    well i cant seem to find a way to do that, i have also create this funny post in stackoverflow with that matter :) c# - Checking if data exist in sqlite-net before inserting them to database - Stack Overflow[^]

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #36

                    Are you trying to compare bitmaps, or simply looking for a way to do an insert-query while checking if there's already such a record? In pseudo, comparing bitmaps would be similar to below;

                    Bitmap bitmap1 = (get bitmap from somewhere)
                    string hashedImage = MakeMD5(bitmap1);
                    Bitmap compareTo = (get bitmap you want to compare to)
                    string compareToHash = MakeMD5(compareTo);
                    bool imagesAreEqual = (hashedImage == compareToHash);

                    That's not helping though if you are trying an insert that does an update when the record is already there.

                    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                    E 1 Reply Last reply
                    0
                    • L Lost User

                      Are you trying to compare bitmaps, or simply looking for a way to do an insert-query while checking if there's already such a record? In pseudo, comparing bitmaps would be similar to below;

                      Bitmap bitmap1 = (get bitmap from somewhere)
                      string hashedImage = MakeMD5(bitmap1);
                      Bitmap compareTo = (get bitmap you want to compare to)
                      string compareToHash = MakeMD5(compareTo);
                      bool imagesAreEqual = (hashedImage == compareToHash);

                      That's not helping though if you are trying an insert that does an update when the record is already there.

                      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                      E Offline
                      E Offline
                      Exoskeletor
                      wrote on last edited by
                      #37

                      I just want to insert a template in the database only if does not exist. By not exist i mean the List of images to not exist in another template. The only solution i can think of is a predefined hash value

                      L 1 Reply Last reply
                      0
                      • E Exoskeletor

                        I just want to insert a template in the database only if does not exist. By not exist i mean the List of images to not exist in another template. The only solution i can think of is a predefined hash value

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #38

                        Exoskeletor wrote:

                        I just want to insert a template in the database only if does not exist.

                        :D You don't need a hash for that, sorry for pointing you in the wrong direction :rolleyes: Instead of an insert-command you usually use, you can use the "INSERT OR REPLACE" command; see SQLite REPLACE: Insert or Replace The Existing Row[^]

                        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                        E 1 Reply Last reply
                        0
                        • L Lost User

                          Exoskeletor wrote:

                          I just want to insert a template in the database only if does not exist.

                          :D You don't need a hash for that, sorry for pointing you in the wrong direction :rolleyes: Instead of an insert-command you usually use, you can use the "INSERT OR REPLACE" command; see SQLite REPLACE: Insert or Replace The Existing Row[^]

                          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                          E Offline
                          E Offline
                          Exoskeletor
                          wrote on last edited by
                          #39

                          but how can sqlite know to replace a record? both my tables have a primary unique key

                          [Table("Templates")]
                          public class Template
                          {
                          [PrimaryKey, AutoIncrement]
                          public int Id { get; set; }
                          public int Category { get; set; }
                          //[TextBlob("imagesBlobbed")]
                          [OneToMany, Unique]
                          public List TemplateImages { get; set; }
                          public string ImagesHash { get; set; }
                          //public string imagesBlobbed { get; set; }
                          }
                          [Table("TemplateImages")]
                          public class TemplateImage
                          {
                          [PrimaryKey, AutoIncrement]
                          public int Id { get; set; }
                          public int Category { get; set; }
                          public string ImagesHash { get; set; }
                          public int Image { get; set; }
                          [ForeignKey(typeof(Template))]
                          public int TemplateId { get; set; }
                          }

                          doesnt that make them unique. Also, this is replacing items according to the primary key it says? so if i have a template with id 5, and i delete it one day, the template that belong to id 6 wll go to the position of id 5? and so on?

                          E L 2 Replies Last reply
                          0
                          • E Exoskeletor

                            but how can sqlite know to replace a record? both my tables have a primary unique key

                            [Table("Templates")]
                            public class Template
                            {
                            [PrimaryKey, AutoIncrement]
                            public int Id { get; set; }
                            public int Category { get; set; }
                            //[TextBlob("imagesBlobbed")]
                            [OneToMany, Unique]
                            public List TemplateImages { get; set; }
                            public string ImagesHash { get; set; }
                            //public string imagesBlobbed { get; set; }
                            }
                            [Table("TemplateImages")]
                            public class TemplateImage
                            {
                            [PrimaryKey, AutoIncrement]
                            public int Id { get; set; }
                            public int Category { get; set; }
                            public string ImagesHash { get; set; }
                            public int Image { get; set; }
                            [ForeignKey(typeof(Template))]
                            public int TemplateId { get; set; }
                            }

                            doesnt that make them unique. Also, this is replacing items according to the primary key it says? so if i have a template with id 5, and i delete it one day, the template that belong to id 6 wll go to the position of id 5? and so on?

                            E Offline
                            E Offline
                            Exoskeletor
                            wrote on last edited by
                            #40

                            also i tried in this code

                            public static void AddTemplate(int category, List images)
                            {
                            var templateDB = new TemplateDB();
                            var imageByteList = new List();

                                    foreach (int image in images)
                                    {
                                        //imageByteList.Add(templateDB.DrawableToByteArray(image));
                                    }
                                    var tmpl = new Template()
                                    {
                                        Category = category,
                                    };
                                    var img1 = new TemplateImage()
                                    {
                                        Category = category,
                                        Image = images\[0\],
                                        //ImagesHash = DatabaseHelper.GetMD5Hash(imageByteList\[0\]),
                                    };
                                    var img2 = new TemplateImage()
                                    {
                                        Category = category,
                                        Image = images\[1\],
                                        //ImagesHash = DatabaseHelper.GetMD5Hash(imageByteList\[1\]),
                                    };
                                    var img3 = new TemplateImage()
                                    {
                                        Category = category,
                                        Image = images\[2\],
                                        //ImagesHash = DatabaseHelper.GetMD5Hash(imageByteList\[2\]),
                                    };
                                    var img4 = new TemplateImage()
                                    {
                                        Category = category,
                                        Image = images\[3\],
                                        //ImagesHash = DatabaseHelper.GetMD5Hash(imageByteList\[3\]),
                                    };
                                    var img5 = new TemplateImage()
                                    {
                                        Category = category,
                                        Image = images\[4\],
                                        //ImagesHash = DatabaseHelper.GetMD5Hash(imageByteList\[4\]),
                                    };
                                    tmpl.TemplateImages = new List() { img1, img2, img3, img4, img5 };
                                    //tmpl.ImagesHash = DatabaseHelper.GetMD5Hash(ConcatByteList(imageByteList));
                                    var result = DatabaseHelper.db().Query("Select \* from Templates where ImagesHash=?", tmpl.ImagesHash);
                                    if (result.Count == 0)
                                    {
                                    DatabaseHelper.db().InsertAll(tmpl.TemplateImages);
                                    DatabaseHelper.db().Insert(tmpl);
                                    DatabaseHelper.db().UpdateWithChildren(tmpl);
                                    }
                            

                            to replace insert with insertorupdate and my template database was empty. id was always 0 in every attemp to insert something to db, do you know why? here is the database structure

                            [Table("Templates")]
                            public class Template
                            {
                            [PrimaryKey, AutoIncrement]
                            public int Id { get; set; }
                            public int Category { get; set; }
                            //[TextBlob("imagesBlobbed")

                            L 1 Reply Last reply
                            0
                            • E Exoskeletor

                              but how can sqlite know to replace a record? both my tables have a primary unique key

                              [Table("Templates")]
                              public class Template
                              {
                              [PrimaryKey, AutoIncrement]
                              public int Id { get; set; }
                              public int Category { get; set; }
                              //[TextBlob("imagesBlobbed")]
                              [OneToMany, Unique]
                              public List TemplateImages { get; set; }
                              public string ImagesHash { get; set; }
                              //public string imagesBlobbed { get; set; }
                              }
                              [Table("TemplateImages")]
                              public class TemplateImage
                              {
                              [PrimaryKey, AutoIncrement]
                              public int Id { get; set; }
                              public int Category { get; set; }
                              public string ImagesHash { get; set; }
                              public int Image { get; set; }
                              [ForeignKey(typeof(Template))]
                              public int TemplateId { get; set; }
                              }

                              doesnt that make them unique. Also, this is replacing items according to the primary key it says? so if i have a template with id 5, and i delete it one day, the template that belong to id 6 wll go to the position of id 5? and so on?

                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #41

                              The page that I linked to lets you try the SQL statements online :) Hadn't seen that it is a real "replace", not an insert "or" update; but it explains that too. It does look like it honors the unique constraint, so should work with a primary key too.

                              Exoskeletor wrote:

                              so if i have a template with id 5, and i delete it one day, the template that belong to id 6 wll go to the position of id 5? and so on?

                              Id's that have been used already do not get re-used; so if you delete 5 and 6 exists, another insert would give you 7, not 5, even if that position is empty.

                              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                              1 Reply Last reply
                              0
                              • E Exoskeletor

                                also i tried in this code

                                public static void AddTemplate(int category, List images)
                                {
                                var templateDB = new TemplateDB();
                                var imageByteList = new List();

                                        foreach (int image in images)
                                        {
                                            //imageByteList.Add(templateDB.DrawableToByteArray(image));
                                        }
                                        var tmpl = new Template()
                                        {
                                            Category = category,
                                        };
                                        var img1 = new TemplateImage()
                                        {
                                            Category = category,
                                            Image = images\[0\],
                                            //ImagesHash = DatabaseHelper.GetMD5Hash(imageByteList\[0\]),
                                        };
                                        var img2 = new TemplateImage()
                                        {
                                            Category = category,
                                            Image = images\[1\],
                                            //ImagesHash = DatabaseHelper.GetMD5Hash(imageByteList\[1\]),
                                        };
                                        var img3 = new TemplateImage()
                                        {
                                            Category = category,
                                            Image = images\[2\],
                                            //ImagesHash = DatabaseHelper.GetMD5Hash(imageByteList\[2\]),
                                        };
                                        var img4 = new TemplateImage()
                                        {
                                            Category = category,
                                            Image = images\[3\],
                                            //ImagesHash = DatabaseHelper.GetMD5Hash(imageByteList\[3\]),
                                        };
                                        var img5 = new TemplateImage()
                                        {
                                            Category = category,
                                            Image = images\[4\],
                                            //ImagesHash = DatabaseHelper.GetMD5Hash(imageByteList\[4\]),
                                        };
                                        tmpl.TemplateImages = new List() { img1, img2, img3, img4, img5 };
                                        //tmpl.ImagesHash = DatabaseHelper.GetMD5Hash(ConcatByteList(imageByteList));
                                        var result = DatabaseHelper.db().Query("Select \* from Templates where ImagesHash=?", tmpl.ImagesHash);
                                        if (result.Count == 0)
                                        {
                                        DatabaseHelper.db().InsertAll(tmpl.TemplateImages);
                                        DatabaseHelper.db().Insert(tmpl);
                                        DatabaseHelper.db().UpdateWithChildren(tmpl);
                                        }
                                

                                to replace insert with insertorupdate and my template database was empty. id was always 0 in every attemp to insert something to db, do you know why? here is the database structure

                                [Table("Templates")]
                                public class Template
                                {
                                [PrimaryKey, AutoIncrement]
                                public int Id { get; set; }
                                public int Category { get; set; }
                                //[TextBlob("imagesBlobbed")

                                L Offline
                                L Offline
                                Lost User
                                wrote on last edited by
                                #42

                                Not quite sure what the code in the DatabaseHelper does, but it looks like you're executing a SELECT statement, not an INSERT.

                                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                                E 1 Reply Last reply
                                0
                                • L Lost User

                                  Not quite sure what the code in the DatabaseHelper does, but it looks like you're executing a SELECT statement, not an INSERT.

                                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                                  E Offline
                                  E Offline
                                  Exoskeletor
                                  wrote on last edited by
                                  #43

                                  With insert the database works but on every app run it reenters the data. with insertorupdate nothing is insert in the database, i read it 2-3 times the page but i cant understand what i'm doing wrong

                                  L 1 Reply Last reply
                                  0
                                  • L Lost User

                                    That's reading all the images and making one big array of bytes of it; may be a bit much for the memorymanager.

                                    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                                    E Offline
                                    E Offline
                                    Exoskeletor
                                    wrote on last edited by
                                    #44

                                    insert or update and insert or replace doesnt work with autoincrement fields [^] so i guess again i'm stuck in generating my own guid and use them, or i should run insertorupdate if the database already exist while manually giving the id's starting from Id 1. guid sounds better idea

                                    L 1 Reply Last reply
                                    0
                                    • E Exoskeletor

                                      With insert the database works but on every app run it reenters the data. with insertorupdate nothing is insert in the database, i read it 2-3 times the page but i cant understand what i'm doing wrong

                                      L Offline
                                      L Offline
                                      Lost User
                                      wrote on last edited by
                                      #45

                                      You're not recreating the database/overwriting it each time it runs, I hope?

                                      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                                      E 1 Reply Last reply
                                      0
                                      • E Exoskeletor

                                        insert or update and insert or replace doesnt work with autoincrement fields [^] so i guess again i'm stuck in generating my own guid and use them, or i should run insertorupdate if the database already exist while manually giving the id's starting from Id 1. guid sounds better idea

                                        L Offline
                                        L Offline
                                        Lost User
                                        wrote on last edited by
                                        #46

                                        Nothing against Guids; and the order in which the inserts are done is usually not guaranteed, so an autoincrement-assignment may not always be in the exact same order.

                                        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                                        E 1 Reply Last reply
                                        0
                                        • L Lost User

                                          You're not recreating the database/overwriting it each time it runs, I hope?

                                          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                                          E Offline
                                          E Offline
                                          Exoskeletor
                                          wrote on last edited by
                                          #47

                                          thats why im trying to check if the entry exist, in order to not recreate it. this is the whole point of my question. how to create data once and only check if it exist in the next run. i just show that guid's doesnt change forever, on the same project, so i will use this, i will mark it as unique in the db structure, and everything will work amazingly good i hope :) Is there any other way of checking if data already exist? i dont like the idea of checking if the table exist, what if only the half data have been created and after that the app crash? what is the proper way to verify and create data in a database?

                                          L 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups