Skip to content

Commit f4f571d

Browse files
committed
Code cleanup
1 parent 9b62cb5 commit f4f571d

File tree

3 files changed

+4
-174
lines changed

3 files changed

+4
-174
lines changed

SQLiteSharp/ColumnMap.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public class ColumnMap {
1111
public bool AutoIncrement { get; }
1212
public bool PrimaryKey { get; }
1313
public bool NotNull { get; }
14-
public int? MaxStringLength { get; }
1514
public IndexedAttribute[] Indexes { get; }
1615

1716
public ColumnMap(MemberInfo member, Orm? orm = null) {
@@ -34,7 +33,6 @@ public ColumnMap(MemberInfo member, Orm? orm = null) {
3433
}
3534

3635
NotNull = PrimaryKey || Orm.IsNotNullConstrained(member);
37-
MaxStringLength = Orm.GetMaxStringLength(member);
3836
}
3937

4038
public void SetValue(object obj, object? value) {

SQLiteSharp/SQLiteCommand.cs

Lines changed: 4 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ public IEnumerable<T> ExecuteQuery<T>() {
6363
public T ExecuteScalar<T>() {
6464
T Value = default!;
6565

66-
Sqlite3Statement stmt = Prepare();
66+
Sqlite3Statement statement = Prepare();
6767

6868
try {
69-
Result result = SQLiteRaw.Step(stmt);
69+
Result result = SQLiteRaw.Step(statement);
7070
if (result is Result.Row) {
71-
object? columnValue = Connection.Orm.ReadColumn(stmt, 0, typeof(T));
71+
object? columnValue = Connection.Orm.ReadColumn(statement, 0, typeof(T));
7272
if (columnValue is not null) {
7373
Value = (T)columnValue;
7474
}
@@ -80,7 +80,7 @@ public T ExecuteScalar<T>() {
8080
}
8181
}
8282
finally {
83-
SQLiteRaw.Finalize(stmt);
83+
SQLiteRaw.Finalize(statement);
8484
}
8585

8686
return Value;
@@ -125,165 +125,6 @@ private void BindParameters(Sqlite3Statement statement) {
125125
}
126126
}
127127

128-
/*internal static void BindParameter(Sqlite3Statement stmt, int index, object? value) {
129-
if (value is null) {
130-
SQLiteRaw.BindNull(stmt, index);
131-
}
132-
else {
133-
if (value is int intValue) {
134-
SQLiteRaw.BindInt(stmt, index, intValue);
135-
}
136-
else if (value is string stringValue) {
137-
SQLiteRaw.BindText(stmt, index, stringValue);
138-
}
139-
else if (value is byte or sbyte or ushort or ushort) {
140-
SQLiteRaw.BindInt(stmt, index, Convert.ToInt32(value));
141-
}
142-
else if (value is bool boolValue) {
143-
SQLiteRaw.BindInt(stmt, index, boolValue ? 1 : 0);
144-
}
145-
else if (value is uint or long or ulong) {
146-
SQLiteRaw.BindInt64(stmt, index, Convert.ToInt64(value));
147-
}
148-
else if (value is float or double or decimal) {
149-
SQLiteRaw.BindDouble(stmt, index, Convert.ToDouble(value));
150-
}
151-
else if (value is TimeSpan timeSpanValue) {
152-
SQLiteRaw.BindInt64(stmt, index, timeSpanValue.Ticks);
153-
}
154-
else if (value is DateTime dateTimeValue) {
155-
SQLiteRaw.BindInt64(stmt, index, dateTimeValue.Ticks);
156-
}
157-
else if (value is DateTimeOffset dateTimeOffsetValue) {
158-
SQLiteRaw.BindBlob(stmt, index, DateTimeOffsetToBytes(dateTimeOffsetValue));
159-
}
160-
else if (value is byte[] byteArrayValue) {
161-
SQLiteRaw.BindBlob(stmt, index, byteArrayValue);
162-
}
163-
else if (value is Guid or StringBuilder or Uri or UriBuilder) {
164-
SQLiteRaw.BindText(stmt, index, value.ToString()!);
165-
}
166-
else {
167-
// Now we could possibly get an enum, retrieve cached info
168-
Type valueType = value.GetType();
169-
if (valueType.IsEnum) {
170-
if (valueType.GetCustomAttribute<StoreByNameAttribute>() is not null) {
171-
SQLiteRaw.BindText(stmt, index, Enum.GetName(valueType, value)!);
172-
}
173-
else {
174-
SQLiteRaw.BindInt(stmt, index, Convert.ToInt32(value));
175-
}
176-
}
177-
else {
178-
throw new NotSupportedException($"Cannot store type: {value.GetType()}");
179-
}
180-
}
181-
}
182-
}*/
183-
184-
/*private static object? ReadColumn(Sqlite3Statement stmt, int index, ColumnType type, Type clrType) {
185-
if (type is ColumnType.Null) {
186-
return null;
187-
}
188-
else {
189-
if (Nullable.GetUnderlyingType(clrType) is Type underlyingType) {
190-
clrType = underlyingType;
191-
}
192-
193-
if (clrType == typeof(string)) {
194-
return SQLiteRaw.GetColumnText(stmt, index);
195-
}
196-
else if (clrType == typeof(int)) {
197-
return SQLiteRaw.GetColumnInt(stmt, index);
198-
}
199-
else if (clrType == typeof(bool)) {
200-
return SQLiteRaw.GetColumnInt(stmt, index) == 1;
201-
}
202-
else if (clrType == typeof(double)) {
203-
return SQLiteRaw.GetColumnDouble(stmt, index);
204-
}
205-
else if (clrType == typeof(float)) {
206-
return (float)SQLiteRaw.GetColumnDouble(stmt, index);
207-
}
208-
else if (clrType == typeof(TimeSpan)) {
209-
return new TimeSpan(SQLiteRaw.GetColumnInt64(stmt, index));
210-
}
211-
else if (clrType == typeof(DateTime)) {
212-
return new DateTime(SQLiteRaw.GetColumnInt64(stmt, index));
213-
}
214-
else if (clrType == typeof(DateTimeOffset)) {
215-
return BytesToDateTimeOffset(SQLiteRaw.GetColumnBlob(stmt, index));
216-
}
217-
else if (clrType.IsEnum) {
218-
if (type is ColumnType.Text) {
219-
string value = SQLiteRaw.GetColumnText(stmt, index);
220-
return Enum.Parse(clrType, value, true);
221-
}
222-
else {
223-
return SQLiteRaw.GetColumnInt(stmt, index);
224-
}
225-
}
226-
else if (clrType == typeof(long)) {
227-
return SQLiteRaw.GetColumnInt64(stmt, index);
228-
}
229-
else if (clrType == typeof(ulong)) {
230-
return (ulong)SQLiteRaw.GetColumnInt64(stmt, index);
231-
}
232-
else if (clrType == typeof(uint)) {
233-
return (uint)SQLiteRaw.GetColumnInt64(stmt, index);
234-
}
235-
else if (clrType == typeof(decimal)) {
236-
return (decimal)SQLiteRaw.GetColumnDouble(stmt, index);
237-
}
238-
else if (clrType == typeof(byte)) {
239-
return (byte)SQLiteRaw.GetColumnInt(stmt, index);
240-
}
241-
else if (clrType == typeof(ushort)) {
242-
return (ushort)SQLiteRaw.GetColumnInt(stmt, index);
243-
}
244-
else if (clrType == typeof(short)) {
245-
return (short)SQLiteRaw.GetColumnInt(stmt, index);
246-
}
247-
else if (clrType == typeof(sbyte)) {
248-
return (sbyte)SQLiteRaw.GetColumnInt(stmt, index);
249-
}
250-
else if (clrType == typeof(byte[])) {
251-
return SQLiteRaw.GetColumnBlob(stmt, index);
252-
}
253-
else if (clrType == typeof(Guid)) {
254-
string text = SQLiteRaw.GetColumnText(stmt, index);
255-
return new Guid(text);
256-
}
257-
else if (clrType == typeof(Uri)) {
258-
string text = SQLiteRaw.GetColumnText(stmt, index);
259-
return new Uri(text);
260-
}
261-
else if (clrType == typeof(StringBuilder)) {
262-
string text = SQLiteRaw.GetColumnText(stmt, index);
263-
return new StringBuilder(text);
264-
}
265-
else if (clrType == typeof(UriBuilder)) {
266-
string text = SQLiteRaw.GetColumnText(stmt, index);
267-
return new UriBuilder(text);
268-
}
269-
else {
270-
throw new NotSupportedException("Don't know how to read " + clrType);
271-
}
272-
}
273-
}*/
274-
275-
internal static DateTimeOffset BytesToDateTimeOffset(byte[] bytes) {
276-
long dateTicks = BitConverter.ToInt64(bytes, 0);
277-
long offsetTicks = BitConverter.ToInt64(bytes, sizeof(long));
278-
return new DateTimeOffset(new DateTime(dateTicks), TimeSpan.FromTicks(offsetTicks));
279-
}
280-
internal static byte[] DateTimeOffsetToBytes(DateTimeOffset dateTimeOffset) {
281-
return [
282-
.. BitConverter.GetBytes(dateTimeOffset.DateTime.Ticks),
283-
.. BitConverter.GetBytes(dateTimeOffset.Offset.Ticks)
284-
];
285-
}
286-
287128
private record struct Parameter(string? Name, object? Value) {
288129
public string? Name { get; set; } = Name;
289130
public object? Value { get; set; } = Value;

SQLiteSharp/SQLiteRaw.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using SQLitePCL;
2-
using System;
32

43
namespace SQLiteSharp;
54

@@ -289,12 +288,4 @@ private SqliteValue(byte[]? @blob) {
289288
public static implicit operator SqliteValue(double? value) => new(value);
290289
public static implicit operator SqliteValue(string? value) => new(value);
291290
public static implicit operator SqliteValue(byte[]? value) => new(value);
292-
293-
/*public static explicit operator long(SqliteValue value) => (long)value.AsObject!;
294-
public static explicit operator double(SqliteValue value) => (double)value.AsObject!;
295-
public static explicit operator string(SqliteValue value) => (string)value.AsObject!;
296-
public static explicit operator byte[](SqliteValue value) => (byte[])value.AsObject!;*/
297-
298-
/*public static explicit operator long?(SqliteValue value) => (long?)value.AsObject;
299-
public static explicit operator double?(SqliteValue value) => (double?)value.AsObject;*/
300291
}

0 commit comments

Comments
 (0)