0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

cscの作法 その530

Posted at

概要

cscの作法、調べてみた。
練習問題やってみた。

練習問題

sqlite3でboolを使え。

方針

  • create table, insert into, select やってみる。

サンプルコード



using System;
using System.Text;
using System.IO;
using System.Data.SQLite;

namespace App
{
	public class Program {
		public static void Main(string[] args) {
			bool check = true;
			Console.WriteLine(check ? "Checked" : "Not checked");
			SQLiteConnectionStringBuilder ConnectionStr = new SQLiteConnectionStringBuilder();
			ConnectionStr.DataSource = "db0.sqlite";
			using (SQLiteConnection Connection = new SQLiteConnection(ConnectionStr.ToString()))
			{
				Connection.Open();
				using(SQLiteCommand Command = new SQLiteCommand(Connection))
				{
					Console.WriteLine("DROP TABLE");
					Command.CommandText = "DROP TABLE user";
					Command.ExecuteNonQuery();
					Console.WriteLine("create table");
					Command.CommandText = "create table user(id integer primary key, name text, updttm text, use bool)";
					Command.ExecuteNonQuery();
					Console.WriteLine("insert x 3");
					Command.CommandText = "insert into user(id, name, updttm, use) values(1, 'hoge', '2022-10-26', True)";
					Command.ExecuteNonQuery();
					Command.CommandText = "insert into user(id, name, updttm, use) values(2, 'fuga', '2022-10-27', False)";
					Command.ExecuteNonQuery();
					Command.CommandText = "insert into user(id, name, updttm, use) values(3, 'piyo', '2022-10-28', True)";
					Command.ExecuteNonQuery();
					Console.WriteLine("SELECTE");
					Command.CommandText = "SELECT * FROM user";
					using (SQLiteDataReader Reader = Command.ExecuteReader())
					{
						while (Reader.Read())
						{
							int Id = Reader.GetInt32(0);
							string Name = Reader.GetString(1);
							string Updttm = Reader.GetString(2);
							bool Use = Reader.GetBoolean(3);
							Console.WriteLine(string.Format("id: {0} name: {1} updttm: {2} use: {3}", Id, Name, Updttm, Use));
						}
					}
				}
			}
		}
	}
}





実行結果

>sql0
Checked
DROP TABLE
create table
insert x 3
SELECTE
id: 1 name: hoge updttm: 2022-10-26 use: True
id: 2 name: fuga updttm: 2022-10-27 use: False
id: 3 name: piyo updttm: 2022-10-28 use: True

以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?