Skip to content

Commit 543bd30

Browse files
committed
Sqlite
- fix wrong cased guids
1 parent bd15f2f commit 543bd30

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

Examples/Sqlite/ToDatabase/Person.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ public class Person
1919
public DateTime Birthday { get; set; } = DateTime.Today;
2020
public int Age { get; set; }
2121
public string Address { get; set; }
22+
public Guid Uid { get; set; }
2223
}
2324
}

Examples/Sqlite/ToDatabase/PersonRepository.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ------------------------------------------------------------------------------
22
// <auto-generated>
3-
// This code was generated with KY.Generator 7.3.0.0
3+
// This code was generated with KY.Generator 7.3.1.0
44
//
55
// Manual changes to this file may cause unexpected behavior in your application.
66
// Manual changes to this file will be overwritten if the code is regenerated.
@@ -15,7 +15,7 @@
1515

1616
namespace ToDatabase
1717
{
18-
[GeneratedCode("KY.Generator", "7.3.0.0")]
18+
[GeneratedCode("KY.Generator", "7.3.1.0")]
1919
public partial class PersonRepository
2020
{
2121
private SqliteConnection connection;
@@ -36,7 +36,8 @@ CREATE TABLE IF NOT EXISTS Person
3636
LastName TEXT not null,
3737
Birthday TEXT not null,
3838
Age INTEGER not null,
39-
Address TEXT
39+
Address TEXT,
40+
Uid TEXT not null
4041
);";
4142
command.ExecuteNonQuery();
4243
}
@@ -52,7 +53,7 @@ public List<Person> Get(string filter = null)
5253
{
5354
using SqliteCommand command = this.connection.CreateCommand();
5455
command.CommandText = @"
55-
SELECT Id, FirstName, LastName, Birthday, Age, Address
56+
SELECT Id, FirstName, LastName, Birthday, Age, Address, Uid
5657
FROM Person";
5758
List<Person> result = new List<Person>();
5859
if (! string.IsNullOrEmpty(filter))
@@ -69,6 +70,7 @@ public List<Person> Get(string filter = null)
6970
entry.Birthday = reader.GetDateTime(3);
7071
entry.Age = reader.GetInt32(4);
7172
entry.Address = reader.IsDBNull(5) ? null : reader.GetString(5);
73+
entry.Uid = reader.GetGuid(6);
7274
result.Add(entry);
7375
}
7476
return result;
@@ -77,13 +79,14 @@ public List<Person> Get(string filter = null)
7779
public Int32 Insert(Person entry)
7880
{
7981
using SqliteCommand command = this.connection.CreateCommand();
80-
command.CommandText = @"INSERT INTO Person (FirstName, LastName, Birthday, Age, Address) VALUES (@firstName, @lastName, @birthday, @age, @address);
82+
command.CommandText = @"INSERT INTO Person (FirstName, LastName, Birthday, Age, Address, Uid) VALUES (@firstName, @lastName, @birthday, @age, @address, @uid);
8183
SELECT last_insert_rowid();";
8284
command.Parameters.Add(new SqliteParameter("@firstName", entry.FirstName));
8385
command.Parameters.Add(new SqliteParameter("@lastName", entry.LastName));
8486
command.Parameters.Add(new SqliteParameter("@birthday", entry.Birthday));
8587
command.Parameters.Add(new SqliteParameter("@age", entry.Age));
8688
command.Parameters.Add(new SqliteParameter("@address", entry.Address ?? (object) DBNull.Value));
89+
command.Parameters.Add(new SqliteParameter("@uid", entry.Uid.ToString()));
8790
return (Int32)(long) command.ExecuteScalar();
8891
}
8992

@@ -96,14 +99,16 @@ UPDATE Person
9699
LastName = @lastName,
97100
Birthday = @birthday,
98101
Age = @age,
99-
Address = @address
102+
Address = @address,
103+
Uid = @uid
100104
WHERE Id = @id";
101105
command.Parameters.Add(new SqliteParameter("@id", entry.Id));
102106
command.Parameters.Add(new SqliteParameter("@firstName", entry.FirstName));
103107
command.Parameters.Add(new SqliteParameter("@lastName", entry.LastName));
104108
command.Parameters.Add(new SqliteParameter("@birthday", entry.Birthday));
105109
command.Parameters.Add(new SqliteParameter("@age", entry.Age));
106110
command.Parameters.Add(new SqliteParameter("@address", entry.Address ?? (object) DBNull.Value));
111+
command.Parameters.Add(new SqliteParameter("@uid", entry.Uid));
107112
command.ExecuteNonQuery();
108113
}
109114

Sqlite/Writers/SqliteRepositoryWriter.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,12 @@ private void WriteInsert(ClassTemplate classTemplate, FieldTemplate connectionFi
199199
foreach (SqlitePropertyTransferObject column in columns)
200200
{
201201
ICodeFragment valueCode = Code.Local("entry").Field(column.Name);
202-
if (!column.IsNotNull && (column.Type.Original?.IsNullable ?? column.Type.IsNullable))
202+
if (column.Type.Original.Name == nameof(Guid))
203+
{
204+
classTemplate.AddUsing("System");
205+
valueCode = valueCode.CastTo<ExecuteFieldTemplate>().Method("ToString");
206+
}
207+
else if (!column.IsNotNull && (column.Type.Original?.IsNullable ?? column.Type.IsNullable))
203208
{
204209
classTemplate.AddUsing("System");
205210
valueCode = Code.NullCoalescing(valueCode, Code.Cast(Code.Type("object")).Local(nameof(DBNull)).Field("Value"));

0 commit comments

Comments
 (0)