Skip to content

Commit fdb5786

Browse files
author
Aingeru
committed
code review
1 parent ecfdf9b commit fdb5786

19 files changed

Lines changed: 1383 additions & 1410 deletions
Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,60 @@
11
using Microsoft.Data.Sqlite;
22
using SqlServer2SqLite.Core.Models;
33
using SQLServer2SQLite.Core.Helpers;
4-
using System;
54
using System.Collections.Generic;
65
using System.Data;
76
using System.Text;
87

9-
namespace SQLServer2SQLite.Core.Builders
8+
namespace SQLServer2SQLite.Core.Builders;
9+
10+
public class InsertBuilder
1011
{
11-
public class InsertBuilder
12+
/// <summary>
13+
/// Creates a command object needed to insert values into a specific SQLite table.
14+
/// </summary>
15+
/// <param name="tableSchema">The table schema object for the table.</param>
16+
/// <returns>A command object with the required functionality.</returns>
17+
// TODO test!
18+
public static SqliteCommand BuildSQLiteInsert(TableSchema tableSchema)
1219
{
13-
/// <summary>
14-
/// Creates a command object needed to insert values into a specific SQLite table.
15-
/// </summary>
16-
/// <param name="tableSchema">The table schema object for the table.</param>
17-
/// <returns>A command object with the required functionality.</returns>
18-
// TODO test!
19-
public static SqliteCommand BuildSQLiteInsert(TableSchema tableSchema)
20-
{
21-
SqliteCommand res = new SqliteCommand();
20+
SqliteCommand res = new SqliteCommand();
2221

23-
StringBuilder sb = new StringBuilder();
24-
sb.Append("INSERT INTO [" + tableSchema.TableName + "] (");
25-
for (int i = 0; i < tableSchema.Columns.Count; i++)
26-
{
27-
sb.Append("[" + tableSchema.Columns[i].ColumnName + "]");
28-
if (i < tableSchema.Columns.Count - 1)
29-
sb.Append(", ");
30-
}
31-
sb.Append(") VALUES (");
22+
StringBuilder sb = new StringBuilder();
23+
sb.Append("INSERT INTO [" + tableSchema.TableName + "] (");
24+
for (int i = 0; i < tableSchema.Columns.Count; i++)
25+
{
26+
sb.Append("[" + tableSchema.Columns[i].ColumnName + "]");
27+
if (i < tableSchema.Columns.Count - 1)
28+
sb.Append(", ");
29+
}
30+
sb.Append(") VALUES (");
3231

33-
List<string> pnames = new List<string>();
34-
for (int i = 0; i < tableSchema.Columns.Count; i++)
35-
{
36-
string pname =
37-
"@" + TextHelper.GetNormalizedName(tableSchema.Columns[i].ColumnName, pnames);
38-
sb.Append(pname);
39-
if (i < tableSchema.Columns.Count - 1)
40-
sb.Append(", ");
32+
List<string> pnames = new List<string>();
33+
for (int i = 0; i < tableSchema.Columns.Count; i++)
34+
{
35+
string pname =
36+
"@" + TextHelper.GetNormalizedName(tableSchema.Columns[i].ColumnName, pnames);
37+
sb.Append(pname);
38+
if (i < tableSchema.Columns.Count - 1)
39+
sb.Append(", ");
4140

42-
SqliteType dbType = ColumnSchema.GetSqLiteDbTypeOfColumn(
43-
tableSchema.Columns[i].ColumnType
44-
);
45-
SqliteParameter prm = new SqliteParameter(
46-
pname,
47-
dbType,
48-
1,
49-
tableSchema.Columns[i].ColumnName
50-
);
51-
res.Parameters.Add(prm);
41+
SqliteType dbType = ColumnSchema.GetSqLiteDbTypeOfColumn(
42+
tableSchema.Columns[i].ColumnType
43+
);
44+
SqliteParameter prm = new SqliteParameter(
45+
pname,
46+
dbType,
47+
1,
48+
tableSchema.Columns[i].ColumnName
49+
);
50+
res.Parameters.Add(prm);
5251

53-
// Remember the parameter name in order to avoid duplicates
54-
pnames.Add(pname);
55-
}
56-
sb.Append(")");
57-
res.CommandText = sb.ToString();
58-
res.CommandType = CommandType.Text;
59-
return res;
52+
// Remember the parameter name in order to avoid duplicates
53+
pnames.Add(pname);
6054
}
55+
sb.Append(")");
56+
res.CommandText = sb.ToString();
57+
res.CommandType = CommandType.Text;
58+
return res;
6159
}
6260
}

0 commit comments

Comments
 (0)