Exemplo n.º 1
0
        public override bool LoadLogImages(List<Framework.Data.LogImage> logimgs)
        {
            bool result = false;
            SqliteConnection dbcon = new SqliteConnection(string.Format("data source=file:{0}", Properties.Settings.Default.ActiveDataFile));
            if (dbcon != null && InitDatabase(dbcon))
            {
                int logimgCount = 0;
                using (SqliteCommand cmd = new SqliteCommand("select logimage from counter", dbcon))
                using (SqliteDataReader dr = cmd.ExecuteReader())
                    if (dr.Read())
                    {
                        logimgCount = (int)dr["logimage"];
                    }

                int index = 0;
                int procStep = 0;
                using (SqliteCommand cmd = new SqliteCommand("select * from logimage", dbcon))
                using (SqliteDataReader dr = cmd.ExecuteReader())
                    while (dr.Read())
                    {
                        Framework.Data.LogImage lg = new Framework.Data.LogImage();

                        lg.ID = (string)dr["id"];
                        lg.LogID = (string)dr["logid"];
                        lg.Url = (string)dr["url"];
                        lg.Name = (string)dr["name"];
                        lg.DataFromDate = DateTime.Parse((string)dr["datafromdate"]).ToLocalTime();

                        lg.Saved = true;
                        lg.IsDataChanged = false;

                        _logimgsInDB[lg.ID] = lg.ID;
                        logimgs.Add(lg);

                        index++;
                        procStep++;
                        if (procStep >= 2000)
                        {
                            UpdateLoadingInBackgroundProgress(STR_LOADING_LOGIMAGES_BG, logimgCount, index);
                            procStep = 0;
                        }
                    }

                dbcon.Dispose();
                dbcon = null;
            }
            return result;
        }
Exemplo n.º 2
0
        public override bool LoadLogs(List<Framework.Data.Log> logs)
        {
            bool result = false;
            SqliteConnection dbcon = new SqliteConnection(string.Format("data source=file:{0}", Properties.Settings.Default.ActiveDataFile));
            if (dbcon != null && InitDatabase(dbcon))
            {
                int logCount = 0;
                using (SqliteCommand cmd = new SqliteCommand("select log from counter", dbcon))
                using (SqliteDataReader dr = cmd.ExecuteReader())
                    if (dr.Read())
                    {
                        logCount = (int)dr["log"];
                    }
                UpdateLoadingInBackgroundProgress(STR_LOADING_LOGS_BG, logCount, 0);

                int index = 0;
                int procStep = 0;
                using (SqliteCommand cmd = new SqliteCommand("select ID, gccode, Finder, DataFromDate, LogType, Date from log", dbcon))
                {
                    cmd.CommandTimeout = 0;
                    using (SqliteDataReader dr = cmd.ExecuteReader())
                        while (dr.Read())
                        {
                            Framework.Data.Log lg = new Framework.Data.Log();

                            lg.ID = (string)dr["id"];
                            lg.GeocacheCode = (string)dr["gccode"];
                            lg.Date = DateTime.Parse((string)dr["date"]).ToLocalTime();
                            lg.Finder = (string)dr["finder"];
                            lg.DataFromDate = DateTime.Parse((string)dr["datafromdate"]).ToLocalTime();
                            lg.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, (int)(int)dr["logtype"]);

                            lg.Saved = true;
                            lg.IsDataChanged = false;

                            _logsInDB[lg.ID] = lg.ID;
                            logs.Add(lg);

                            index++;
                            procStep++;
                            if (procStep >= 20000)
                            {
                                UpdateLoadingInBackgroundProgress(STR_LOADING_LOGS_BG, logCount, index);
                                procStep = 0;
                            }
                        }
                }
                dbcon.Dispose();
                dbcon = null;
            }
            return result;
        }
Exemplo n.º 3
0
        public override bool LoadWaypoints(List<Framework.Data.Waypoint> wps, List<Framework.Data.UserWaypoint> usrwps)
        {
            bool result = false;
            SqliteConnection dbcon = new SqliteConnection(string.Format("data source=file:{0}", Properties.Settings.Default.ActiveDataFile));
            if (dbcon != null && InitDatabase(dbcon))
            {
                int wptCount = 0;
                using (SqliteCommand cmd = new SqliteCommand("select waypoint from counter", dbcon))
                using (SqliteDataReader dr = cmd.ExecuteReader())
                    if (dr.Read())
                    {
                        wptCount = (int)dr["waypoint"];
                    }

                int index = 0;
                int procStep = 0;
                using (SqliteCommand cmd = new SqliteCommand("select * from waypoint", dbcon))
                {
                    cmd.CommandTimeout = 0;
                    using (SqliteDataReader dr = cmd.ExecuteReader())
                        while (dr.Read())
                        {
                            Framework.Data.Waypoint wp = new Framework.Data.Waypoint();

                            wp.ID = (string)dr["id"];
                            wp.Code = (string)dr["code"];
                            wp.Url = (string)dr["url"];
                            wp.UrlName = (string)dr["urlname"];
                            wp.Name = (string)dr["name"];
                            wp.DataFromDate = DateTime.Parse((string)dr["datafromdate"]).ToLocalTime();
                            wp.Comment = (string)dr["comment"];
                            wp.GeocacheCode = (string)dr["geocachecode"];
                            wp.Description = (string)dr["description"];
                            wp.WPType = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, (int)(int)dr["wptype"]);
                            object o = dr["lat"];
                            if (o == null || o.GetType() == typeof(DBNull))
                            {
                                wp.Lat = null;
                            }
                            else
                            {
                                wp.Lat = (double?)o;
                            }
                            o = dr["lon"];
                            if (o == null || o.GetType() == typeof(DBNull))
                            {
                                wp.Lon = null;
                            }
                            else
                            {
                                wp.Lon = (double?)o;
                            }
                            wp.Time = DateTime.Parse((string)dr["time"]).ToLocalTime();

                            wp.Saved = true;
                            wp.IsDataChanged = false;

                            _wptsInDB[wp.Code] = wp.Code;
                            wps.Add(wp);

                            index++;
                            procStep++;
                            if (procStep >= 20000)
                            {
                                UpdateLoadingInBackgroundProgress(STR_LOADING_WAYPOINTS_BG, wptCount, index);
                                procStep = 0;
                            }
                        }
                }
                using (SqliteCommand cmd = new SqliteCommand("select * from userwaypoint", dbcon))
                {
                    cmd.CommandTimeout = 0;
                    using (SqliteDataReader dr = cmd.ExecuteReader())
                        while (dr.Read())
                        {
                            Framework.Data.UserWaypoint wp = new Framework.Data.UserWaypoint();

                            wp.ID = (int)(int)dr["id"];
                            wp.GeocacheCode = (string)dr["geocachecode"];
                            wp.Description = (string)dr["description"];
                            wp.Lat = (double)dr["lat"];
                            wp.Lon = (double)dr["lon"];
                            wp.Date = DateTime.Parse((string)dr["time"]).ToLocalTime();

                            wp.Saved = true;
                            wp.IsDataChanged = false;

                            _usrwptsInDB[wp.ID] = wp.ID;
                            usrwps.Add(wp);
                        }
                }

                dbcon.Dispose();
                dbcon = null;
            }
            return result;
        }
    public void Issue_65()
    {
      //alxwest: causes error "Unable to open database" as TempDirectory.ToString() is set to "B:/TEMP/"
      //string datasource = "file://" + TempDirectory.ToString() + "myBigDb.s3db";
      string datasource = "file://" + "myBigDb.s3db";

      using (IDbConnection conn = new SqliteConnection("uri=" + datasource))
      {
        long targetFileSize = (long)Math.Pow(2, 32) - 1;
        int rowLength = 1024; // 2^10

        long loopCount = (int)(targetFileSize / rowLength) + 10000;

        char[] chars = new char[rowLength];
        for (int i = 0; i < rowLength; i++)
        {
          chars[i] = 'A';
        }

        string row = new string(chars);

        conn.Open();
        IDbCommand cmd = conn.CreateCommand();

        try
        {
          cmd.CommandText = "PRAGMA cache_size = 16000; PRAGMA synchronous = OFF; PRAGMA journal_mode = MEMORY;";
          cmd.ExecuteNonQuery();

          cmd.CommandText = "drop table if exists [MyTable]";
          cmd.ExecuteNonQuery();

          cmd.CommandText = "create table [MyTable] ([MyField] varchar(" + rowLength + ") null)";
          cmd.ExecuteNonQuery();

          cmd.CommandText = "insert into [MyTable] ([MyField]) VALUES ('" + row + "')";
          for (int i = 0; i < loopCount; i++)
          {
            cmd.ExecuteNonQuery();
          }
        }
        catch
        {
          Console.WriteLine(((SqliteCommand)cmd).GetLastError());
        }
        finally
        {
          cmd.Cancel();
          conn.Close();
          conn.Dispose();
        }
      }

    }