테이블 처리 string > StringBuilder변경
This commit is contained in:
parent
a8ab7ae6c5
commit
610f6dc30c
|
|
@ -4,6 +4,7 @@ using Npgsql;
|
||||||
using Server.SQL;
|
using Server.SQL;
|
||||||
using Server.System;
|
using Server.System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace Server.Git
|
namespace Server.Git
|
||||||
{
|
{
|
||||||
|
|
@ -30,87 +31,86 @@ namespace Server.Git
|
||||||
|
|
||||||
// 쿼리 작성 및 실행
|
// 쿼리 작성 및 실행
|
||||||
//모든 쿼리 삭제
|
//모든 쿼리 삭제
|
||||||
string query;
|
StringBuilder query;
|
||||||
string header1 = "CREATE TABLE excel.";
|
string header1 = "CREATE TABLE excel.";
|
||||||
string header2 = "INSERT INTO excel.";
|
string header2 = "INSERT INTO excel.";
|
||||||
string newTableQuery;
|
StringBuilder newTableQuery;
|
||||||
string tableDatas;
|
StringBuilder tableDatas = new StringBuilder();
|
||||||
#region 모든 테이블 삭제
|
#region 모든 테이블 삭제
|
||||||
query = "DROP SCHEMA excel CASCADE;" +
|
ExecuteNonQuery(connection, "DROP SCHEMA excel CASCADE;CREATE SCHEMA excel AUTHORIZATION manager;");
|
||||||
"CREATE SCHEMA excel AUTHORIZATION manager;";
|
|
||||||
ExecuteNonQuery(connection, query);
|
|
||||||
#endregion
|
#endregion
|
||||||
#region 테이블 세팅
|
#region 테이블 세팅
|
||||||
query = "";
|
query = new StringBuilder();
|
||||||
for (int n = 0; n < sheets.Count; n++)
|
for (int n = 0; n < sheets.Count; n++)
|
||||||
{
|
{
|
||||||
//초기화
|
//초기화
|
||||||
newTableQuery = "";
|
newTableQuery = new StringBuilder();
|
||||||
tableDatas = "(";
|
tableDatas.Append("(");
|
||||||
|
|
||||||
#region 신규 테이블 생성
|
#region 신규 테이블 생성
|
||||||
newTableQuery += header1;
|
newTableQuery.Append(header1);
|
||||||
newTableQuery += sheets[n].name + "(";
|
newTableQuery.Append(sheets[n].name);
|
||||||
|
newTableQuery.Append("(");
|
||||||
for (int m = 0; m < sheets[n].variable.Count; m++)
|
for (int m = 0; m < sheets[n].variable.Count; m++)
|
||||||
{
|
{
|
||||||
if (sheets[n].dataEnum[m] == "client")
|
if (sheets[n].dataEnum[m] == "client")
|
||||||
continue;
|
continue;
|
||||||
if (sheets[n].type[m] == "long" && sheets[n].variable[m] == "index")
|
if (sheets[n].type[m] == "long" && sheets[n].variable[m] == "index")
|
||||||
{
|
{
|
||||||
newTableQuery += "index SERIAL PRIMARY KEY";
|
newTableQuery.Append("index SERIAL PRIMARY KEY");
|
||||||
tableDatas += "index";
|
tableDatas.Append("index");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (m != 0)
|
if (m != 0)
|
||||||
{
|
{
|
||||||
newTableQuery += ",";
|
newTableQuery.Append(",");
|
||||||
tableDatas += ", ";
|
tableDatas.Append(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (sheets[n].type[m])
|
switch (sheets[n].type[m])
|
||||||
{
|
{
|
||||||
case "bool":
|
case "bool":
|
||||||
newTableQuery += $"{sheets[n].variable[m]} BOOL ";
|
newTableQuery.Append($"{sheets[n].variable[m]} BOOL ");
|
||||||
break;
|
break;
|
||||||
case "int":
|
case "int":
|
||||||
newTableQuery += $"{sheets[n].variable[m]} INT ";
|
newTableQuery.Append($"{sheets[n].variable[m]} INT ");
|
||||||
break;
|
break;
|
||||||
case "long":
|
case "long":
|
||||||
newTableQuery += $"{sheets[n].variable[m]} LONG ";
|
newTableQuery.Append($"{sheets[n].variable[m]} LONG ");
|
||||||
break;
|
break;
|
||||||
case "float":
|
case "float":
|
||||||
newTableQuery += $"{sheets[n].variable[m]} FLOAT4 ";
|
newTableQuery.Append($"{sheets[n].variable[m]} FLOAT4 ");
|
||||||
break;
|
break;
|
||||||
case "string":
|
case "string":
|
||||||
case "json":
|
case "json":
|
||||||
newTableQuery += $"{sheets[n].variable[m]} VARCHAR(255) ";
|
newTableQuery.Append($"{sheets[n].variable[m]} VARCHAR(255) ");
|
||||||
break;
|
break;
|
||||||
case "enum":
|
case "enum":
|
||||||
newTableQuery += $"{sheets[n].variable[m]} INT2 ";
|
newTableQuery.Append($"{sheets[n].variable[m]} INT2 ") ;
|
||||||
break;
|
break;
|
||||||
case "text":
|
case "text":
|
||||||
newTableQuery += $"{sheets[n].variable[m]} TEXT ";
|
newTableQuery.Append($"{sheets[n].variable[m]} TEXT ");
|
||||||
break;
|
break;
|
||||||
case "time":
|
case "time":
|
||||||
newTableQuery += $"{sheets[n].variable[m]} timestamp ";
|
newTableQuery.Append($"{sheets[n].variable[m]} timestamp ");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
logger.Error($"unknown data {sheets[n].type[m]}");
|
logger.Error($"unknown data {sheets[n].type[m]}");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
tableDatas += sheets[n].variable[m];
|
tableDatas.Append(sheets[n].variable[m]);
|
||||||
}
|
}
|
||||||
newTableQuery += ");\n";
|
newTableQuery.Append(");\n");
|
||||||
tableDatas += ") VALUES ";
|
tableDatas.Append(") VALUES ");
|
||||||
bool isStart = true;
|
bool isStart = true;
|
||||||
query += newTableQuery;
|
query.Append(newTableQuery.ToString());
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
#region 신규 테이블 데이터 올리기
|
#region 신규 테이블 데이터 올리기
|
||||||
|
|
||||||
query += header2;
|
query.Append(header2);
|
||||||
query += sheets[n].name;
|
query.Append(sheets[n].name);
|
||||||
query += tableDatas;
|
query.Append(tableDatas.ToString());
|
||||||
foreach(KeyValuePair<long, Dictionary<string, object>> pair in sheets[n].dicViewer)
|
foreach(KeyValuePair<long, Dictionary<string, object>> pair in sheets[n].dicViewer)
|
||||||
{
|
{
|
||||||
if (isStart)
|
if (isStart)
|
||||||
|
|
@ -119,16 +119,16 @@ namespace Server.Git
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
query += ", ";
|
query.Append(", ");
|
||||||
}
|
}
|
||||||
query += "(";
|
query.Append("(");
|
||||||
for (int m = 0; m < sheets[n].variable.Count; m++)
|
for (int m = 0; m < sheets[n].variable.Count; m++)
|
||||||
{
|
{
|
||||||
if (sheets[n].dataEnum[m] == "client")
|
if (sheets[n].dataEnum[m] == "client")
|
||||||
continue;
|
continue;
|
||||||
if (m != 0)
|
if (m != 0)
|
||||||
{
|
{
|
||||||
query += ", ";
|
query.Append(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (sheets[n].type[m])
|
switch (sheets[n].type[m])
|
||||||
|
|
@ -138,27 +138,27 @@ namespace Server.Git
|
||||||
case "int":
|
case "int":
|
||||||
case "float":
|
case "float":
|
||||||
case "long":
|
case "long":
|
||||||
query += $"{pair.Value[sheets[n].variable[m]]}";
|
query.Append($"{pair.Value[sheets[n].variable[m]]}");
|
||||||
break;
|
break;
|
||||||
case "string":
|
case "string":
|
||||||
case "json":
|
case "json":
|
||||||
case "text":
|
case "text":
|
||||||
query += $"'{pair.Value[sheets[n].variable[m]]}'";
|
query.Append($"'{pair.Value[sheets[n].variable[m]]}'");
|
||||||
break;
|
break;
|
||||||
case "time":
|
case "time":
|
||||||
query += $"'{((DateTime)pair.Value[sheets[n].variable[m]]).ToString("yyyy-MM-dd HH:mm:ss")}'";
|
query.Append($"'{((DateTime)pair.Value[sheets[n].variable[m]]).ToString("yyyy-MM-dd HH:mm:ss")}'");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
logger.Error($"unknown data value {sheets[n].type[m]}");
|
logger.Error($"unknown data value {sheets[n].type[m]}");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
query += ")";
|
query.Append(")");
|
||||||
}
|
}
|
||||||
query += ";";
|
query.Append(";");
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
ExecuteNonQuery(connection, query);
|
ExecuteNonQuery(connection, query.ToString());
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue