コード例 #1
0
        public LemmaRepository(LemmaDatabase db, string tableName, string[] columnNames)
        {
            Database   = db;
            TableName  = tableName;
            ColumNames = columnNames;

            InsertCmd = db.CreateCommand("insert into " + TableName + "(word," + string.Join(",", columnNames)
                                         + ") values(@word, @" + string.Join(", @", columnNames) + ")");
            InsertCmd.Prepare();
            string[] columnSetters = columnNames.Select(x => x + "=@" + x).ToArray(); // x=@x
            UpdateCmd = db.CreateCommand("update " + TableName + " set word=@word, " + string.Join(", ", columnSetters) + " where id=@id");
            UpdateCmd.Prepare();
            DeleteCmd = db.CreateCommand("delete from " + TableName + " where id=@id");
            DeleteCmd.Prepare();
            CountCmd = db.CreateCommand("select count(*) from " + TableName);
            CountCmd.Prepare();
            SelectByIdCmd = db.CreateCommand("select * from " + TableName + " where id=@id");
            SelectByIdCmd.Prepare();
            SelectPageOfDataCmd = db.CreateCommand("select * from " + TableName + " limit @pageSize offset @offset");
            SelectPageOfDataCmd.Prepare();
        }