main
syneffort 2 years ago
parent 4d60e97363
commit 702bac7e6e
  1. 19
      SQLite_Console/PsqLiteWrapper/App.config
  2. 116
      SQLite_Console/PsqLiteWrapper/PSqLite.cs
  3. 81
      SQLite_Console/PsqLiteWrapper/PSqLiteWrapper.csproj
  4. 36
      SQLite_Console/PsqLiteWrapper/Properties/AssemblyInfo.cs
  5. 9
      SQLite_Console/PsqLiteWrapper/packages.config
  6. 10
      SQLite_Console/SQLite_Console.sln
  7. 167
      SQLite_Console/SQLite_Console/Program.cs
  8. 6
      SQLite_Console/SQLite_Console/SQLite_Console.csproj

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite.EF6" />
<add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
<remove invariant="System.Data.SQLite" /><add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" /></DbProviderFactories>
</system.data>
</configuration>

@ -0,0 +1,116 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PSqLiteWrapper
{
public static class PSqLite
{
public static string DBPath { get; set; }
private static string ConnString
{
get { return $@"Data Source = {DBPath};"; }
}
public static SQLiteConnection Connection
{
get
{
if (string.IsNullOrEmpty(DBPath))
throw new ArgumentException("Empty DBPath");
try
{
return new SQLiteConnection(ConnString);
}
catch (Exception ex)
{
throw ex;
}
}
}
public static void CreateDB()
{
if (string.IsNullOrEmpty(DBPath))
throw new ArgumentException("Empty DBPath");
try
{
if (!File.Exists(DBPath))
SQLiteConnection.CreateFile(DBPath);
}
catch (Exception ex)
{
throw ex;
}
}
public static void ExecuteQuery(string query)
{
if (string.IsNullOrEmpty(DBPath))
throw new ArgumentException("Empty DBPath");
try
{
using (SQLiteConnection conn = Connection)
{
conn.Open();
SQLiteCommand command = new SQLiteCommand(query, conn);
command.ExecuteNonQuery();
Connection.Close();
}
}
catch (Exception ex)
{
throw ex;
}
}
public static void ExecuteQuery(SQLiteConnection openedConn, string query)
{
SQLiteCommand command = new SQLiteCommand(query, openedConn);
command.ExecuteNonQuery();
}
public static DataSet ExecuteSelectQuery(string query)
{
if (string.IsNullOrEmpty(DBPath))
throw new ArgumentException("Empty DBPath");
try
{
using (SQLiteConnection conn = Connection)
{
DataSet dataSet = new DataSet();
conn.Open();
SQLiteDataAdapter adapter = new SQLiteDataAdapter(query, conn);
adapter.Fill(dataSet);
Connection.Close();
return dataSet;
}
}
catch (Exception ex)
{
throw ex;
}
}
public static DataSet ExecuteSelectQuery(SQLiteConnection openedConn, string query)
{
DataSet dataSet = new DataSet();
SQLiteDataAdapter adapter = new SQLiteDataAdapter(query, openedConn);
adapter.Fill(dataSet);
return dataSet;
}
}
}

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\EntityFramework.6.4.4\build\EntityFramework.props" Condition="Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{24FE639E-FC41-4AE9-8682-838E07E5BCA9}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PSqLiteWrapper</RootNamespace>
<AssemblyName>PSqLiteWrapper</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Data.SQLite, Version=1.0.117.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.117.0\lib\net45\System.Data.SQLite.dll</HintPath>
</Reference>
<Reference Include="System.Data.SQLite.EF6, Version=1.0.117.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.EF6.1.0.117.0\lib\net45\System.Data.SQLite.EF6.dll</HintPath>
</Reference>
<Reference Include="System.Data.SQLite.Linq, Version=1.0.117.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.Linq.1.0.117.0\lib\net45\System.Data.SQLite.Linq.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PSqLite.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>이 프로젝트는 이 컴퓨터에 없는 NuGet 패키지를 참조합니다. 해당 패키지를 다운로드하려면 NuGet 패키지 복원을 사용하십시오. 자세한 내용은 http://go.microsoft.com/fwlink/?LinkID=322105를 참조하십시오. 누락된 파일은 {0}입니다.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.4\build\EntityFramework.props'))" />
<Error Condition="!Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.4\build\EntityFramework.targets'))" />
<Error Condition="!Exists('..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.117.0\build\net45\Stub.System.Data.SQLite.Core.NetFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.117.0\build\net45\Stub.System.Data.SQLite.Core.NetFramework.targets'))" />
</Target>
<Import Project="..\packages\EntityFramework.6.4.4\build\EntityFramework.targets" Condition="Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.targets')" />
<Import Project="..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.117.0\build\net45\Stub.System.Data.SQLite.Core.NetFramework.targets" Condition="Exists('..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.117.0\build\net45\Stub.System.Data.SQLite.Core.NetFramework.targets')" />
</Project>

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해
// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면
// 이러한 특성 값을 변경하세요.
[assembly: AssemblyTitle("PSqLiteWrapper")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PsqLiteWrapper")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에
// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요.
[assembly: ComVisible(false)]
// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
[assembly: Guid("24fe639e-fc41-4ae9-8682-838e07e5bca9")]
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 버전
//
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를
// 기본값으로 할 수 있습니다.
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.4.4" targetFramework="net45" />
<package id="Stub.System.Data.SQLite.Core.NetFramework" version="1.0.117.0" targetFramework="net45" />
<package id="System.Data.SQLite" version="1.0.117.0" targetFramework="net45" />
<package id="System.Data.SQLite.Core" version="1.0.117.0" targetFramework="net45" />
<package id="System.Data.SQLite.EF6" version="1.0.117.0" targetFramework="net45" />
<package id="System.Data.SQLite.Linq" version="1.0.117.0" targetFramework="net45" />
</packages>

@ -1,10 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.32630.194
# Visual Studio Version 17
VisualStudioVersion = 17.3.32929.385
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SQLite_Console", "SQLite_Console\SQLite_Console.csproj", "{A4457E3F-0254-45B1-B1AF-6196AA25B9B9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PSqLiteWrapper", "PsqLiteWrapper\PSqLiteWrapper.csproj", "{24FE639E-FC41-4AE9-8682-838E07E5BCA9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -15,6 +17,10 @@ Global
{A4457E3F-0254-45B1-B1AF-6196AA25B9B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4457E3F-0254-45B1-B1AF-6196AA25B9B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4457E3F-0254-45B1-B1AF-6196AA25B9B9}.Release|Any CPU.Build.0 = Release|Any CPU
{24FE639E-FC41-4AE9-8682-838E07E5BCA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{24FE639E-FC41-4AE9-8682-838E07E5BCA9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{24FE639E-FC41-4AE9-8682-838E07E5BCA9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{24FE639E-FC41-4AE9-8682-838E07E5BCA9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -1,10 +1,15 @@
using System;
using PSqLiteWrapper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
namespace SQLite_Console
@ -13,60 +18,106 @@ namespace SQLite_Console
{
static void Main(string[] args)
{
string connString = @"Data Source = D:\SQLite\mydb.db";
using (SQLiteConnection conn = new SQLiteConnection(connString))
string dbFileName = "mydb.db";
string path = Assembly.GetExecutingAssembly().CodeBase;
string dir = Path.GetDirectoryName(path).Replace(@"file:\", "");
Stopwatch watch = new Stopwatch();
watch.Start();
PSqLite.DBPath = $@"{dir}\{dbFileName}";
PSqLite.CreateDB();
watch.Stop();
Console.WriteLine($"database check: {watch.ElapsedMilliseconds}ms");
Console.WriteLine();
watch.Restart();
// Create table
PSqLite.ExecuteQuery(
@"CREATE TABLE 'member' (
'name' TEXT,
'age' INTEGER,
'guid' TEXT
);");
watch.Stop();
Console.WriteLine($"create table: {watch.ElapsedMilliseconds}ms");
Console.WriteLine();
watch.Restart();
List<Thread> threads = new List<Thread>();
for (int i = 0; i < 20; i++)
{
Stopwatch watch = new Stopwatch();
watch.Start();
threads.Add(new Thread(() => InsertRandomRows($"t{i + 1}", 1000)));
}
conn.Open();
foreach (Thread thread in threads)
{
thread.Start();
}
watch.Stop();
Console.WriteLine($"open: {watch.ElapsedMilliseconds}ms");
Console.WriteLine();
watch.Restart();
//Random rnd = new Random();
//for (int i = 0; i < 2000; i++)
//{
// string guid = Guid.NewGuid().ToString();
// int age = rnd.Next(1, 100);
// string name = $"Robo#{i + 1}";
// string insertQry = $"INSERT INTO member VALUES ('{name}', {age}, '{guid}')";
// PSqLite.ExecuteQuery(insertQry);
//}
Random rnd = new Random();
for (int i = 0; i < 2000; i++)
{
string guid = Guid.NewGuid().ToString();
int age = rnd.Next(1, 100);
string name = $"Robot#{i + 1}";
string insertQry = $"INSERT INTO member VALUES ('{name}', {age}, '{guid}')";
SQLiteCommand cmd = new SQLiteCommand(insertQry, conn);
cmd.ExecuteNonQuery();
}
//watch.Stop();
//Console.WriteLine($"insert 2000 row case1: {watch.ElapsedMilliseconds}ms");
//Console.WriteLine();
//watch.Restart();
watch.Stop();
Console.WriteLine($"insert: {watch.ElapsedMilliseconds}ms");
Console.WriteLine();
watch.Restart();
//rnd = new Random();
//using (SQLiteConnection conn = PSqLite.Connection)
//{
// conn.Open();
// for (int i = 0; i < 2000; i++)
// {
// string guid = Guid.NewGuid().ToString();
// int age = rnd.Next(1, 100);
// string name = $"Robo#{i + 1}";
// string insertQry = $"INSERT INTO member VALUES ('{name}', {age}, '{guid}')";
// PSqLite.ExecuteQuery(conn, insertQry);
// }
DataSet ds = new DataSet();
string selectQry = "SELECT * FROM member";
SQLiteDataAdapter adt = new SQLiteDataAdapter(selectQry, conn);
adt.Fill(ds);
// conn.Close();
//}
DataRowCollection rows = ds.Tables[0].Rows;
PrintRows(rows);
//watch.Stop();
//Console.WriteLine($"insert 2000 row case2: {watch.ElapsedMilliseconds}ms");
//Console.WriteLine();
//watch.Restart();
watch.Stop();
Console.WriteLine($"select all: {watch.ElapsedMilliseconds}ms");
Console.WriteLine();
watch.Restart();
//DataSet select = PSqLite.ExecuteSelectQuery("SELECT * FROM member");
//DataRowCollection rows = select.Tables[0].Rows;
////PrintRows(rows);
selectQry = "SELECT * FROM member WHERE age < 50";
adt = new SQLiteDataAdapter(selectQry, conn);
adt.Fill(ds);
//watch.Stop();
//Console.WriteLine($"select all: {watch.ElapsedMilliseconds}ms");
//Console.WriteLine();
//watch.Restart();
rows = ds.Tables[0].Rows;
PrintRows(rows);
//PSqLite.ExecuteQuery("UPDATE member SET name = 'minor' WHERE age <= 20");
watch.Stop();
Console.WriteLine($"select under 50: {watch.ElapsedMilliseconds}ms");
Console.WriteLine();
watch.Restart();
}
//watch.Stop();
//Console.WriteLine($"update under 20: {watch.ElapsedMilliseconds}ms");
//Console.WriteLine();
//select = PSqLite.ExecuteSelectQuery("SELECT * FROM member WHERE age <= 20");
//rows = select.Tables[0].Rows;
//watch.Stop();
//Console.WriteLine($"select under 20: {watch.ElapsedMilliseconds}ms");
//Console.WriteLine();
//watch.Restart();
//PrintRows(rows);
Console.ReadKey();
}
@ -83,5 +134,33 @@ namespace SQLite_Console
Console.WriteLine($"name: {name}, age: {age}, guid: {guid}");
}
}
private static void InsertRandomRows(string identifier, int count)
{
Console.WriteLine(identifier);
Stopwatch watch = new Stopwatch();
watch.Start();
Random rnd = new Random();
using (SQLiteConnection conn = PSqLite.Connection)
{
conn.Open();
for (int i = 0; i < count; i++)
{
string guid = Guid.NewGuid().ToString();
int age = rnd.Next(1, 100);
string name = $"{identifier} Robo#{i + 1}";
string insertQry = $"INSERT INTO member VALUES ('{name}', {age}, '{guid}')";
PSqLite.ExecuteQuery(conn, insertQry);
}
conn.Close();
}
watch.Stop();
Console.WriteLine($"insert 2000 row for {identifier}: {watch.ElapsedMilliseconds}ms");
Console.WriteLine();
}
}
}

@ -68,6 +68,12 @@
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PsqLiteWrapper\PSqLiteWrapper.csproj">
<Project>{24fe639e-fc41-4ae9-8682-838e07e5bca9}</Project>
<Name>PSqLiteWrapper</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>

Loading…
Cancel
Save