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


C# SQLiteConnection.ExecuteScalar方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            String veekunFilename;
            ConnectionStringSettings css;

            if (args.Length < 1) veekunFilename = "pokedex.sqlite";
            else veekunFilename = args[0];

            if (veekunFilename.Contains(';')) throw new NotSupportedException("The character ; in filenames is not supported.");
            if (veekunFilename.Contains('?'))
            {
                Console.WriteLine("Usage: VeekunImport [filename [connectionString providerName]]");
                Console.WriteLine("filename: Filename of Veekun sqlite database. Default: pokedex.sqlite");
                Console.WriteLine("connectionString: pkmnFoundations connection string. Default: from app.config");
                Console.WriteLine("providerName: .NET classname of connection provider. Default: from app.config");
                return;
            }

            if (args.Length < 3)
                css = ConfigurationManager.ConnectionStrings["pkmnFoundationsConnectionString"];
            else
                css = new ConnectionStringSettings("", args[1], args[2]);

            Database db = Database.CreateInstance(css);

            using (SQLiteConnection connVeekun = new SQLiteConnection("Data Source=" + veekunFilename + "; Version=3"))
            {
                connVeekun.Open();

                // General logic:
                // 1. run a query against veekun, populate a DataTable.
                // 2. foreach DataRow, instance a class from the PkmnFoundations.Pokedex namespace.
                // 3. call Database.AddToPokedex on that object.

                // todo: We need a way to rebuild specific tables

                // pkmncf_pokedex_pokemon_families
                // Obtain the families map. We will use it in a few places.
                Dictionary<int, int> familyMap = new Dictionary<int, int>();
                List<int[]> familyList = new List<int[]>();
                ProcessTSV("families_map.txt", 1, row =>
                    {
                        // todo: allow for comments by stopping consumption of fields once one fails to parse.
                        int[] fieldsInt = row.Fields.Select(s => Convert.ToInt32(s)).ToArray();
                        familyList.Add(fieldsInt);
                        foreach (int x in fieldsInt)
                        {
                            // lineNumber is one-based, unlike familyList index.
                            // species is the key, family ID is the value.
                            // If any species is repeated in family_map.txt, this ought to fail.
                            familyMap.Add(x, row.ValidLineNumber + 1);
                        }
                    });

                // families from families.txt override default behaviour.
                List<Family> overrideFamilies = new List<Family>();
                ProcessTSV("families.txt", 7, row =>
                    {
                        String[] fields = row.Fields;
                        overrideFamilies.Add(new Family(null,
                            Convert.ToInt32(fields[0]),
                            Convert.ToInt32(fields[1]),
                            Convert.ToInt32(fields[2]),
                            Convert.ToInt32(fields[3]),
                            Convert.ToInt32(fields[4]),
                            Convert.ToInt32(fields[5]),
                            Convert.ToByte(fields[6])
                            ));
                    });
                // already sorted
                //someFamilies.Sort((f, other) => f.ID.CompareTo(other.ID));

                int familyCount = familyList.Count;
                int nextOverrideIndex = 0;
                for (int familyId = 1; familyId <= familyCount; familyId++)
                {
                    int basicSpeciesId = familyList[familyId - 1][0];
                    Family f;
                    if (nextOverrideIndex < overrideFamilies.Count && overrideFamilies[nextOverrideIndex].ID == familyId)
                    {
                        // An override exists in the table; use it.
                        f = overrideFamilies[nextOverrideIndex];
                        nextOverrideIndex++;
                    }
                    else
                    {
                        // No override exists so go with default:
                        // Basic male/female are the same species which is the one listed first.
                        // There is no baby species nor incense
                        // (Non-incense babies are considered basic in this system anyway.)
                        // Gender ratio comes from the basic species.
                        byte genderRatio = (byte)Convert.ToInt32(connVeekun.ExecuteScalar("SELECT gender_rate FROM pokemon_species WHERE id = @id", new SQLiteParameter("@id", basicSpeciesId)));
                        f = new Family(null, familyId, basicSpeciesId, basicSpeciesId, 0, 0, 0, genderRatio);
                    }
                    db.PokedexInsertFamily(f);
                    String basic = (f.BasicMaleID != f.BasicFemaleID) ?
                        String.Format(" {0}/{1}", f.BasicMaleID, f.BasicFemaleID) :
                        String.Format(" {0}", f.BasicMaleID);
                    String baby;
                    if (f.BabyMaleID != f.BabyFemaleID)
//.........这里部分代码省略.........
开发者ID:henias,项目名称:pkmn-classic-framework,代码行数:101,代码来源:Program.cs

示例2: EnsureDbCreated

        void EnsureDbCreated()
        {
            using (var conn = new SQLiteConnection(_connectionString))
            {
                conn.Open();
                if (conn.ExecuteScalar<int>("PRAGMA user_version") == 0)
                {                    
                    conn.Execute(GetDdl());
                    conn.Execute("PRAGMA user_version = 1");

                    _logger.Info($"New SqlLite DB storage created at '{conn.FileName}'");
                }                
            }
        }
开发者ID:alexf2,项目名称:ReactiveWebServerProto,代码行数:14,代码来源:GuestBookSqlLiteProvider.cs


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