当前位置: 首页>>代码示例>>C#>>正文


C# SqliteCommand.ExecuteScalar方法代码示例

本文整理汇总了C#中Community.CsharpSqlite.SQLiteClient.SqliteCommand.ExecuteScalar方法的典型用法代码示例。如果您正苦于以下问题:C# SqliteCommand.ExecuteScalar方法的具体用法?C# SqliteCommand.ExecuteScalar怎么用?C# SqliteCommand.ExecuteScalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Community.CsharpSqlite.SQLiteClient.SqliteCommand的用法示例。


在下文中一共展示了SqliteCommand.ExecuteScalar方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExportMethod

        protected override void ExportMethod()
        {
            try
            {
                using (Utils.ProgressBlock fixscr = new Utils.ProgressBlock(this, STR_EXPORTINGGPX, STR_CREATINGFILE, 1, 0))
                {
                    System.Collections.Hashtable logTypes = new System.Collections.Hashtable();
                    logTypes.Add(2, "Found it");
                    logTypes.Add(3, "Didn't find it");
                    logTypes.Add(4, "Write note");
                    logTypes.Add(5, "Archive");
                    logTypes.Add(7, "Needs Archived");
                    logTypes.Add(9, "Will Attend");
                    logTypes.Add(10, "Attended");
                    logTypes.Add(11, "Webcam Photo Taken");
                    logTypes.Add(12, "Unarchive");
                    logTypes.Add(22, "Temporarily Disable Listing");
                    logTypes.Add(23, "Enable Listing");
                    logTypes.Add(24, "Publish Listing");
                    logTypes.Add(25, "Retract Listing");
                    logTypes.Add(45, "Needs Maintenance");
                    logTypes.Add(46, "Owner Maintenance");
                    logTypes.Add(47, "Update Coordinates");
                    logTypes.Add(68, "Post Reviewer Note");
                    logTypes.Add(74, "Announcement");

                    if (System.IO.File.Exists(_filename))
                    {
                        System.IO.File.Delete(_filename);
                    }

                    using (var strm = Assembly.GetExecutingAssembly().GetManifestResourceStream("GlobalcachingApplication.Plugins.Locus.sqlite.db3"))
                    {
                        byte[] data = new byte[strm.Length];
                        strm.Read(data, 0, data.Length);
                        File.WriteAllBytes(_filename, data);
                    }

                    SqliteConnection dbconFiles = null;
                    string basePath = null;
                    int imgFolderIndex = 0;
                    int imgInFolderCount = 0;
                    if (Properties.Settings.Default.ExportGrabbedImages)
                    {
                        basePath = System.IO.Path.GetDirectoryName(_filename);
                        basePath = System.IO.Path.Combine(basePath, ".GrabbedImages");
                        if (!System.IO.Directory.Exists(basePath))
                        {
                            System.IO.Directory.CreateDirectory(basePath);
                        }
                        if (Properties.Settings.Default.MaxFilesInFolder > 0)
                        {
                            string imgSubFolder = System.IO.Path.Combine(basePath, string.Format("batch{0}", imgFolderIndex));
                            while (System.IO.Directory.Exists(imgSubFolder))
                            {
                                imgFolderIndex++;
                                imgSubFolder = System.IO.Path.Combine(basePath, string.Format("batch{0}", imgFolderIndex));
                            }
                        }
                        dbconFiles = new SqliteConnection(string.Format("data source=file:{0}", System.IO.Path.Combine(basePath, "files.db3")));
                        dbconFiles.Open();
                        using (SqliteCommand cmd = new SqliteCommand("", dbconFiles))
                        {
                            cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='fdone'";
                            object o = cmd.ExecuteScalar();
                            if (o == null || o.GetType() == typeof(DBNull))
                            {
                                cmd.CommandText = "CREATE TABLE fdone (dlink text)";
                                cmd.ExecuteNonQuery();
                                cmd.CommandText = "CREATE INDEX ifdone on fdone (dlink)";
                                cmd.ExecuteNonQuery();
                            }

                            cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='files'";
                            o = cmd.ExecuteScalar();
                            if (o == null || o.GetType() == typeof(DBNull))
                            {
                                cmd.CommandText = "CREATE TABLE files (Link text collate nocase, Fname text collate nocase, Found integer)";
                                cmd.ExecuteNonQuery();
                                cmd.CommandText = "CREATE INDEX ilink on files (Link)";
                                cmd.ExecuteNonQuery();
                                cmd.CommandText = "CREATE INDEX ifname on files (Fname)";
                                cmd.ExecuteNonQuery();
                            }

                            cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='purge'";
                            o = cmd.ExecuteScalar();
                            if (o == null || o.GetType() == typeof(DBNull))
                            {
                                cmd.CommandText = "CREATE TABLE purge (pfile text)";
                                cmd.ExecuteNonQuery();
                            }
                        }
                    }


                    using (SqliteConnection dbcon = new SqliteConnection(string.Format("data source=file:{0}", _filename)))
                    {
                        dbcon.Open();

//.........这里部分代码省略.........
开发者ID:RH-Code,项目名称:GAPP,代码行数:101,代码来源:ExportAddOnGSAKDatabase.cs

示例2: ImportMethod

        protected override void ImportMethod()
        {
            System.Collections.Hashtable logTypes = new System.Collections.Hashtable();
            using (Utils.ProgressBlock fixpr = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGDATA, 1, 0))
            {
                String connect = String.Format("data source=file:{0}", _filename);
                using (SqliteConnection dbcon = new SqliteConnection(connect))
                {

                    //System.Diagnostics.Debugger.Break();
                    logTypes.Add("Found it", 2);
                    logTypes.Add("Didn't find it", 3);
                    logTypes.Add("Write note", 4);
                    logTypes.Add("Archive", 5);
                    logTypes.Add("Needs Archived", 7);
                    logTypes.Add("Will Attend", 9);
                    logTypes.Add("Attended", 10);
                    logTypes.Add("Webcam Photo Taken", 11);
                    logTypes.Add("Unarchive", 12);
                    logTypes.Add("Temporarily Disable Listing", 22);
                    logTypes.Add("Enable Listing", 23);
                    logTypes.Add("Publish Listing", 24);
                    logTypes.Add("Retract Listing", 25);
                    logTypes.Add("Needs Maintenance", 45);
                    logTypes.Add("Owner Maintenance", 46);
                    logTypes.Add("Update Coordinates", 47);
                    logTypes.Add("Post Reviewer Note", 68);
                    logTypes.Add("Announcement", 74);
                    int index = 0;
                    int procStep = 0;

                    dbcon.Open();

                    SqliteCommand lookup = new SqliteCommand("select aId, aInc from attributes where aCode = @Code", dbcon);
                    lookup.CommandType = CommandType.Text;
                    DbParameter par = lookup.CreateParameter();
                    par.Direction = ParameterDirection.Input;
                    par.ParameterName = "@Code";
                    lookup.Parameters.Add(par);
                    lookup.Prepare();

                    SqliteCommand import = new SqliteCommand("select count(1) from caches", dbcon);
                    import.CommandType = CommandType.Text;


                    int gcCount = (int)(long)import.ExecuteScalar();
                    if (gcCount > 0)
                    {
                        using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGGEOCACHES, gcCount, 0))
                        {

                            bool isPremiumAvailable = false;
                            bool isFavPointAvailable = false;
                            bool isGCNoteAvailable = false;

                            try
                            {
                                import.CommandText = "select IsPremium from Caches limit 1";
                                using (SqliteDataReader checkdr = import.ExecuteReader())
                                {
                                    isPremiumAvailable = true;
                                }
                            }
                            catch
                            {
                            }

                            try
                            {
                                import.CommandText = "select FavPoints from Caches limit 1";
                                using (SqliteDataReader checkdr = import.ExecuteReader())
                                {
                                    isFavPointAvailable = true;
                                }
                            }
                            catch
                            {
                            }

                            try
                            {
                                import.CommandText = "select gcnote from Caches limit 1";
                                using (SqliteDataReader checkdr = import.ExecuteReader())
                                {
                                    isGCNoteAvailable = true;
                                }
                            }
                            catch
                            {
                            }

                            import.CommandText = "select caches.Code, Name, LastGPXDate, PlacedDate, Latitude, Longitude, Status, " +
                                "Archived, Country, State, CacheType, PlacedBy, OwnerName, OwnerId, Container, Terrain, Difficulty, ShortHTM" +
                                ", LongHTM, " +
                                string.Format("{0}", isPremiumAvailable? "IsPremium, ":"") +
                                " HasCorrected, LatOriginal, LonOriginal, UserFlag, Found, " +
                                string.Format("{0}", isFavPointAvailable? "FavPoints, ":"") +
                                " ShortDescription, LongDescription, Hints, Url, UserNote" +
                                string.Format("{0}", isGCNoteAvailable ? ", gcnote" : "") +
                                " from caches" +
//.........这里部分代码省略.........
开发者ID:RH-Code,项目名称:GAPP,代码行数:101,代码来源:ImportGSAK.cs

示例3: ExportToGDAK

        public async Task ExportToGDAK(List<Core.Data.Geocache> gcList, string targetFolder, int maxLogCount, bool offlineImages, int maxInImgFolder)
        {
            string filename = Path.Combine(targetFolder, "sqlite.db3");
            await Task.Run(() =>
            {
                try
                {
                    DateTime nextUpdate = DateTime.Now.AddSeconds(1);
                    using (Utils.ProgressBlock fixscr = new Utils.ProgressBlock("ExportingGDAK", "CreatingFile", 1, 0, true))
                    {
                        System.Collections.Hashtable logTypes = new System.Collections.Hashtable();
                        logTypes.Add(2, "Found it");
                        logTypes.Add(3, "Didn't find it");
                        logTypes.Add(4, "Write note");
                        logTypes.Add(5, "Archive");
                        logTypes.Add(7, "Needs Archived");
                        logTypes.Add(9, "Will Attend");
                        logTypes.Add(10, "Attended");
                        logTypes.Add(11, "Webcam Photo Taken");
                        logTypes.Add(12, "Unarchive");
                        logTypes.Add(22, "Temporarily Disable Listing");
                        logTypes.Add(23, "Enable Listing");
                        logTypes.Add(24, "Publish Listing");
                        logTypes.Add(25, "Retract Listing");
                        logTypes.Add(45, "Needs Maintenance");
                        logTypes.Add(46, "Owner Maintenance");
                        logTypes.Add(47, "Update Coordinates");
                        logTypes.Add(68, "Post Reviewer Note");
                        logTypes.Add(74, "Announcement");

                        if (System.IO.File.Exists(filename))
                        {
                            System.IO.File.Delete(filename);
                        }
                        SqliteConnection dbconFiles = null;
                        string basePath = null;
                        int imgFolderIndex = 0;
                        int imgInFolderCount = 0;
                        if (Core.Settings.Default.GDAKExportOfflineImages)
                        {
                            basePath = System.IO.Path.Combine(targetFolder, "GrabbedImages");
                            if (!System.IO.Directory.Exists(basePath))
                            {
                                System.IO.Directory.CreateDirectory(basePath);
                            }
                            if (Core.Settings.Default.GDAKMaxImagesInFolder > 0)
                            {
                                string imgSubFolder = System.IO.Path.Combine(basePath, string.Format("batch{0}", imgFolderIndex));
                                while (System.IO.Directory.Exists(imgSubFolder))
                                {
                                    imgFolderIndex++;
                                    imgSubFolder = System.IO.Path.Combine(basePath, string.Format("batch{0}", imgFolderIndex));
                                }
                            }
                            dbconFiles = new SqliteConnection(string.Format("data source=file:{0}", System.IO.Path.Combine(basePath, "files.db3")));
                            dbconFiles.Open();
                            using (SqliteCommand cmd = new SqliteCommand("", dbconFiles))
                            {
                                cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='fdone'";
                                object o = cmd.ExecuteScalar();
                                if (o == null || o.GetType() == typeof(DBNull))
                                {
                                    cmd.CommandText = "CREATE TABLE fdone (dlink text)";
                                    cmd.ExecuteNonQuery();
                                    cmd.CommandText = "CREATE INDEX ifdone on fdone (dlink)";
                                    cmd.ExecuteNonQuery();
                                }

                                cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='files'";
                                o = cmd.ExecuteScalar();
                                if (o == null || o.GetType() == typeof(DBNull))
                                {
                                    cmd.CommandText = "CREATE TABLE files (Link text collate nocase, Fname text collate nocase, Found integer)";
                                    cmd.ExecuteNonQuery();
                                    cmd.CommandText = "CREATE INDEX ilink on files (Link)";
                                    cmd.ExecuteNonQuery();
                                    cmd.CommandText = "CREATE INDEX ifname on files (Fname)";
                                    cmd.ExecuteNonQuery();
                                }

                                cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='purge'";
                                o = cmd.ExecuteScalar();
                                if (o == null || o.GetType() == typeof(DBNull))
                                {
                                    cmd.CommandText = "CREATE TABLE purge (pfile text)";
                                    cmd.ExecuteNonQuery();
                                }
                            }
                        }
                        using (SqliteConnection dbcon = new SqliteConnection(string.Format("data source=file:{0}", filename)))
                        {
                            dbcon.Open();
                            using (SqliteCommand cmd = new SqliteCommand("", dbcon))
                            {
                                foreach (string s in SQLCREATEDBTABLES)
                                {
                                    cmd.CommandText = s;
                                    cmd.ExecuteNonQuery();
                                }
                                foreach (string s in SQLCREATEDBINDEXES)
//.........这里部分代码省略.........
开发者ID:gahadzikwa,项目名称:GAPP,代码行数:101,代码来源:Export.cs

示例4: InitDatabase

        private bool InitDatabase(SqliteConnection dbcon)
        {
            bool result = false;
            try
            {
                if (dbcon.State == ConnectionState.Closed)
                {
                    dbcon.Open();
                }
                using (SqliteCommand cmd = new SqliteCommand("",dbcon))
                {
                    cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='project_info'";
                    object o = cmd.ExecuteScalar();
                    if (o == null || o.GetType() == typeof(DBNull))
                    {
                        cmd.CommandText = "create table 'project_info' (item_name text, item_value text)";
                        cmd.ExecuteNonQuery();
                    }

                    cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='geocache_cfields'";
                    o = cmd.ExecuteScalar();
                    if (o == null || o.GetType() == typeof(DBNull))
                    {
                        cmd.CommandText = "create table 'geocache_cfields' (field_name text)";
                        cmd.ExecuteNonQuery();
                    }

                    cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='geocache'";
                    o = cmd.ExecuteScalar();
                    if (o == null || o.GetType() == typeof(DBNull))
                    {
                        cmd.CommandText = "create table 'geocache' (id text, code text, name text, datafromdate text, lat real, lon real, disttocent integer, angletocent integer, available integer, archived integer, country text, state text, cachetype integer, placedby text, owner text, ownerid text, container integer, terrain real, difficulty real, shortdescr text, shortdescrhtml integer, longdescr text, longdescrhtml integer, encodedhints text, url text, memberonly integer, customcoords integer, attrids text, favorites integer, selected integer, municipality text, city text, customlat real, customlon real, notes text, publiceddate text, personalnote text, flagged integer, found integer, locked integer)";
                        cmd.ExecuteNonQuery();
                        cmd.CommandText = "create unique index idx_geocache on geocache (code)";
                        cmd.ExecuteNonQuery();
                    }
                    else if (!ColumnExists(dbcon,"geocache","locked"))
                    {
                        cmd.CommandText = "alter table geocache add locked integer";
                        cmd.ExecuteNonQuery();
                        cmd.CommandText = "update geocache set locked=0";
                        cmd.ExecuteNonQuery();
                    }

                    cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='log'";
                    o = cmd.ExecuteScalar();
                    if (o == null || o.GetType() == typeof(DBNull))
                    {
                        cmd.CommandText = "create table 'log' (id text, gccode text, tbcode text, date text, finder text, finderid text, logtext text, encoded integer, datafromdate text, logtype integer)";
                        cmd.ExecuteNonQuery();
                        cmd.CommandText = "create unique index idx_log on log (id)";
                        cmd.ExecuteNonQuery();
                    }

                    cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='logimage'";
                    o = cmd.ExecuteScalar();
                    if (o == null || o.GetType() == typeof(DBNull))
                    {
                        cmd.CommandText = "create table 'logimage' (id text, logid text, url text, name text, datafromdate text)";
                        cmd.ExecuteNonQuery();
                        cmd.CommandText = "create unique index idx_logimage on logimage (id)";
                        cmd.ExecuteNonQuery();
                    }

                    cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='waypoint'";
                    o = cmd.ExecuteScalar();
                    if (o == null || o.GetType() == typeof(DBNull))
                    {
                        cmd.CommandText = "create table 'waypoint' (id text, code text, geocachecode text, name text, datafromdate text, comment text, description text, url text, urlname text, wptype integer, lat real, lon real, time text)";
                        cmd.ExecuteNonQuery();
                        cmd.CommandText = "create unique index idx_waypoint on waypoint (code)";
                        cmd.ExecuteNonQuery();
                    }

                    cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='userwaypoint'";
                    o = cmd.ExecuteScalar();
                    if (o == null || o.GetType() == typeof(DBNull))
                    {
                        cmd.CommandText = "create table 'userwaypoint' (id integer, geocachecode text, description text, lat real, lon real, time text)";
                        cmd.ExecuteNonQuery();
                        cmd.CommandText = "create unique index idx_userwaypoint on userwaypoint (id)";
                        cmd.ExecuteNonQuery();
                    }


                    cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='counter'";
                    o = cmd.ExecuteScalar();
                    if (o == null || o.GetType() == typeof(DBNull))
                    {
                        cmd.CommandText = "create table 'counter' (geocache integer, log integer, waypoint integer, logimage integer)";
                        cmd.ExecuteNonQuery();
                        cmd.CommandText = "insert into counter (geocache, log, waypoint, logimage) values (0, 0, 0, 0)";
                        cmd.ExecuteNonQuery();
                    }
                }
                result = true;
            }
            catch
            {
            }
//.........这里部分代码省略.........
开发者ID:RH-Code,项目名称:GAPP,代码行数:101,代码来源:InternalStorage.cs

示例5: Import

        private static bool Import(Database database, string filename)
        {
            System.Collections.Hashtable logTypes = new System.Collections.Hashtable();
            String connect = String.Format("data source=file:{0}", filename);
            using (SqliteConnection dbcon = new SqliteConnection(connect))
            {

                //System.Diagnostics.Debugger.Break();
                logTypes.Add("Found it", 2);
                logTypes.Add("Didn't find it", 3);
                logTypes.Add("Write note", 4);
                logTypes.Add("Archive", 5);
                logTypes.Add("Needs Archived", 7);
                logTypes.Add("Will Attend", 9);
                logTypes.Add("Attended", 10);
                logTypes.Add("Webcam Photo Taken", 11);
                logTypes.Add("Unarchive", 12);
                logTypes.Add("Temporarily Disable Listing", 22);
                logTypes.Add("Enable Listing", 23);
                logTypes.Add("Publish Listing", 24);
                logTypes.Add("Retract Listing", 25);
                logTypes.Add("Needs Maintenance", 45);
                logTypes.Add("Owner Maintenance", 46);
                logTypes.Add("Update Coordinates", 47);
                logTypes.Add("Post Reviewer Note", 68);
                logTypes.Add("Announcement", 74);

                dbcon.Open();

                SqliteCommand lookup = new SqliteCommand("select aId, aInc from attributes where aCode = @Code", dbcon);
                lookup.CommandType = CommandType.Text;
                DbParameter par = lookup.CreateParameter();
                par.Direction = ParameterDirection.Input;
                par.ParameterName = "@Code";
                lookup.Parameters.Add(par);
                lookup.Prepare();

                SqliteCommand import = new SqliteCommand("select count(1) from caches", dbcon);
                import.CommandType = CommandType.Text;

                int index = 0;
                int gcCount = (int)(long)import.ExecuteScalar();
                if (gcCount > 0)
                {
                    DateTime progShow = DateTime.Now.AddSeconds(1);
                    using (Utils.ProgressBlock prog = new ProgressBlock("Import GSAK database", "Importing...", 1, 0))
                    {
                        bool isPremiumAvailable = false;
                        bool isFavPointAvailable = false;
                        bool isGCNoteAvailable = false;

                        try
                        {
                            import.CommandText = "select IsPremium from Caches limit 1";
                            using (SqliteDataReader checkdr = import.ExecuteReader())
                            {
                                isPremiumAvailable = true;
                            }
                        }
                        catch
                        {
                        }

                        try
                        {
                            import.CommandText = "select FavPoints from Caches limit 1";
                            using (SqliteDataReader checkdr = import.ExecuteReader())
                            {
                                isFavPointAvailable = true;
                            }
                        }
                        catch
                        {
                        }

                        try
                        {
                            import.CommandText = "select gcnote from Caches limit 1";
                            using (SqliteDataReader checkdr = import.ExecuteReader())
                            {
                                isGCNoteAvailable = true;
                            }
                        }
                        catch
                        {
                        }

                        import.CommandText = "select caches.Code, Name, LastGPXDate, PlacedDate, Latitude, Longitude, Status, " +
                            "Archived, Country, State, CacheType, PlacedBy, OwnerName, OwnerId, Container, Terrain, Difficulty, ShortHTM" +
                            ", LongHTM, " +
                            string.Format("{0}", isPremiumAvailable ? "IsPremium, " : "") +
                            " HasCorrected, LatOriginal, LonOriginal, UserFlag, Found, " +
                            string.Format("{0}", isFavPointAvailable ? "FavPoints, " : "") +
                            " ShortDescription, LongDescription, Hints, Url, UserNote" +
                            string.Format("{0}", isGCNoteAvailable ? ", gcnote" : "") +
                            " from caches" +
                            " inner join cachememo on cachememo.code = caches.code";

                        SqliteDataReader dr = import.ExecuteReader();

//.........这里部分代码省略.........
开发者ID:patl12345,项目名称:GAPP,代码行数:101,代码来源:Importer.cs


注:本文中的Community.CsharpSqlite.SQLiteClient.SqliteCommand.ExecuteScalar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。