Skip to content

Commit e6d415f

Browse files
committed
release 1.2.8
- provider resource bugfix to parse column names - provider resource bugfix to get last inserted id - config bugfix with providerName
1 parent 9c556d6 commit e6d415f

10 files changed

+94
-38
lines changed

Databasic.SQLite.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
33
<metadata minClientVersion="2.6">
44
<id>Databasic.SQLite</id>
5-
<version>1.2.6.0</version>
5+
<version>1.2.8.0</version>
66
<title>Databasic - SQLite</title>
77
<authors>Tom Flidr</authors>
88
<owners>Tom Flidr</owners>
@@ -18,7 +18,7 @@
1818
<tags>sql sqlite database query command select insert update delete pure sql dml tool utility library</tags>
1919
<dependencies>
2020
<dependency id="System.Data.SQLite.Core" version="1.0.105.2" />
21-
<dependency id="Databasic.Core" version="1.2.4.0" />
21+
<dependency id="Databasic.Core" version="1.2.8.0" />
2222
</dependencies>
2323
<frameworkAssemblies>
2424
<frameworkAssembly assemblyName="System.Core" />

Databasic.SQLite.vbproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
<PropertyGroup>
4545
<OptionInfer>On</OptionInfer>
4646
</PropertyGroup>
47+
<PropertyGroup>
48+
<SignAssembly>true</SignAssembly>
49+
</PropertyGroup>
50+
<PropertyGroup>
51+
<AssemblyOriginatorKeyFile>Tom Flidr - .NET.pfx</AssemblyOriginatorKeyFile>
52+
</PropertyGroup>
4753
<ItemGroup>
4854
<Reference Include="System" />
4955
<Reference Include="System.Data" />
@@ -107,6 +113,7 @@
107113
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
108114
</None>
109115
<None Include="packages.config" />
116+
<None Include="Tom Flidr - .NET.pfx" />
110117
<None Include="_CreateNewNuGetPackage\Config.ps1" />
111118
<None Include="_CreateNewNuGetPackage\DoNotModify\CreateNuGetPackage.ps1" />
112119
<None Include="_CreateNewNuGetPackage\DoNotModify\New-NuGetPackage.ps1" />

My Project/AssemblyInfo.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ Imports System.Runtime.InteropServices
3434
' by using the '*' as shown below:
3535
' <Assembly: AssemblyVersion("1.0.*")>
3636

37-
<Assembly: AssemblyVersion("1.2.6.0")>
38-
<Assembly: AssemblyFileVersion("1.2.6.0")>
37+
<Assembly: AssemblyVersion("1.2.8.0")>
38+
<Assembly: AssemblyFileVersion("1.2.8.0")>

ProviderResource.vb

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,89 @@
1-
Imports Databasic.ActiveRecord
1+
Imports System.Text.RegularExpressions
2+
Imports Databasic.ActiveRecord
23

34
Public Class ProviderResource
4-
Inherits Databasic.ProviderResource
5+
Inherits Databasic.ProviderResource
56

6-
Public Overrides Function GetTableColumns(table As String, connection As Databasic.Connection) As Dictionary(Of String, Boolean)
7-
Dim result As New Dictionary(Of String, Boolean)
8-
Dim createSql As String = Databasic.Statement.Prepare("
7+
Public Overrides Function GetTableColumns(table As String, connection As Databasic.Connection) As Dictionary(Of String, Boolean)
8+
Dim createSql = Me._getCreateTableStatement(table, connection)
9+
createSql = Me._prepareCreateTableStatement(createSql)
10+
Return Me._parseColumnsFromCreateTable(createSql)
11+
End Function
12+
13+
Private Function _getCreateTableStatement(table As String, connection As Databasic.Connection) As String
14+
Return Databasic.Statement.Prepare("
915
SELECT sql
1016
FROM sqlite_master t
1117
WHERE
1218
t.type = 'table' AND
1319
t.name = @table
14-
",
15-
connection
20+
", connection
1621
).FetchAll(New With {
1722
.table = table
1823
}).ToInstance(Of String)()
19-
Dim pos = createSql.IndexOf("(")
20-
If pos = -1 Then Return result
24+
End Function
25+
26+
Private Function _prepareCreateTableStatement(createSql As String) As String
27+
'' createSql example:
28+
'CREATE TABLE persons (
29+
' id_person INT NOT NULL,
30+
' id_parent INT NULL,
31+
' id_department INT NOT NULL,
32+
' name VARCHAR(100) NOT NULL,
33+
' surname VARCHAR(100) NULL,
34+
' salary DECIMAL(9, 2) NOT NULL DEFAULT 0,
35+
' gender CHAR(1) NOT NULL DEFAULT 'O'
36+
')
37+
Dim result As String = "",
38+
indexPos = 0,
39+
m As Match,
40+
pos = createSql.IndexOf("(")
2141
createSql = createSql.Substring(pos + 1)
2242
pos = createSql.LastIndexOf(")")
23-
If pos = -1 Then Return result
2443
createSql = createSql.Substring(0, pos)
25-
Dim columnsSql As String() = createSql.Split(",")
26-
Dim columnSql As String
27-
Dim columnName As String
28-
Dim columnCouldBeNull As Boolean
44+
' replace temporarily all comma chars in value type definition places
45+
' to be able to split all columns by comma char later
46+
For Each m In Regex.Matches(createSql, "\(\d+(,)\s*\d+\)")
47+
result &= createSql.Substring(indexPos, m.Index - indexPos) _
48+
& m.Value.Replace(",", "__DATABASIC_COMMA_CHAR__")
49+
indexPos = m.Index + m.Length
50+
Next
51+
result &= createSql.Substring(m.Index + m.Length)
52+
' comma replacing end
53+
result = result.Replace("\t", " ").Replace("\r", " ").Replace("\n", " ")
54+
Return result
55+
End Function
56+
57+
Private Function _parseColumnsFromCreateTable(createSql As String) As Object
58+
Dim result As New Dictionary(Of String, Boolean),
59+
columnsSql As String() = createSql.Split(","),
60+
columnSql As String,
61+
columnName As String,
62+
columnCouldBeNull As Boolean,
63+
pos As Int32
2964
For index = 0 To columnsSql.Length - 1
3065
columnSql = columnsSql(index).Trim(" "c, "\t", "\r", "\n")
3166
pos = columnSql.IndexOf(" ")
3267
If (pos = -1) Then Continue For
68+
' columnSql example:
69+
' salary DECIMAL(9__DATABASIC_COMMA_CHAR__ 2) NOT NULL DEFAULT 0
70+
columnSql = columnSql.Replace("__DATABASIC_COMMA_CHAR__", ",")
71+
' columnSql example:
72+
' salary DECIMAL(9, 2) NOT NULL DEFAULT 0
3373
columnName = columnSql.Substring(0, pos)
3474
columnCouldBeNull = columnSql.ToLower().IndexOf("not null") = -1
3575
result.Add(columnName, columnCouldBeNull)
3676
Next
3777
Return result
3878
End Function
3979

40-
Public Overrides Function GetLastInsertedId(ByRef transaction As Databasic.Transaction, Optional ByRef classMetaDescription As MetaDescription = Nothing) As Object
41-
Return Databasic.Statement.Prepare("SELECT LAST_INSERT_ID()", transaction).FetchOne().ToInstance(Of Object)()
80+
Public Overrides Function GetLastInsertedId(
81+
ByRef transaction As Databasic.Transaction,
82+
Optional ByRef classMetaDescription As MetaDescription = Nothing
83+
) As Object
84+
Return Databasic.Statement.Prepare(
85+
"SELECT LAST_INSERT_ROWID()", transaction
86+
).FetchOne().ToInstance(Of Object)()
4287
End Function
4388

4489
'Public Overrides Function GetAll(

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Databasic - SQLite
22

3-
[![Latest Stable Version](https://img.shields.io/badge/Stable-v1.2.6-brightgreen.svg?style=plastic)](https://github.com/databasic-net/databasic-core/releases)
3+
[![Latest Stable Version](https://img.shields.io/badge/Stable-v1.2.8-brightgreen.svg?style=plastic)](https://github.com/databasic-net/databasic-core/releases)
44
[![License](https://img.shields.io/badge/Licence-BSD3-brightgreen.svg?style=plastic)](https://raw.githubusercontent.com/databasic-net/databasic-core/master/LICENCE.md)
55
![.NET Version](https://img.shields.io/badge/.NET->=4.0-brightgreen.svg?style=plastic)
66

Statement.vb

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Imports System.ComponentModel
1+
Imports System.ComponentModel
22
Imports System.Data.Common
33
Imports System.Data.SQLite
44
Imports SQLite.Data.SQLiteClient
@@ -71,14 +71,18 @@ Public Class Statement
7171
''' </summary>
7272
''' <param name="sqlParams">Anonymous object with named keys as MySQL/MariaDB statement params without any '@' chars in object keys.</param>
7373
Protected Overrides Sub addParamsWithValue(sqlParams As Object)
74+
Dim sqlParamValue As Object
7475
If (Not sqlParams Is Nothing) Then
75-
Dim sqlParamValue As Object
7676
For Each prop As PropertyDescriptor In TypeDescriptor.GetProperties(sqlParams)
7777
sqlParamValue = prop.GetValue(sqlParams)
78+
If (sqlParamValue Is Nothing) Then
79+
sqlParamValue = DBNull.Value
80+
Else
81+
sqlParamValue = Me.getPossibleUnderlyingEnumValue(sqlParamValue)
82+
End If
7883
Me._cmd.Parameters.AddWithValue(
79-
prop.Name,
80-
If((sqlParamValue Is Nothing), DBNull.Value, sqlParamValue)
81-
)
84+
prop.Name, sqlParamValue
85+
)
8286
Next
8387
End If
8488
End Sub
@@ -87,18 +91,18 @@ Public Class Statement
8791
''' </summary>
8892
''' <param name="sqlParams">Dictionary with named keys as MySQL/MariaDB statement params without any '@' chars in dictionary keys.</param>
8993
Protected Overrides Sub addParamsWithValue(sqlParams As Dictionary(Of String, Object))
94+
Dim sqlParamValue As Object
9095
If (Not sqlParams Is Nothing) Then
9196
For Each pair As KeyValuePair(Of String, Object) In sqlParams
97+
If (pair.Value Is Nothing) Then
98+
sqlParamValue = DBNull.Value
99+
Else
100+
sqlParamValue = Me.getPossibleUnderlyingEnumValue(pair.Value)
101+
End If
92102
Me._cmd.Parameters.AddWithValue(
93-
pair.Key,
94-
If((pair.Value Is Nothing), DBNull.Value, pair.Value)
95-
)
103+
pair.Key, sqlParamValue
104+
)
96105
Next
97106
End If
98107
End Sub
99-
100-
101-
102-
103-
104108
End Class

content/App.config.install.xdt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<add
66
name="Databasic.Example.SQLite"
77
connectionString="Data Source=.\sqlite.db;Version=3;Password=PASSWORD;"
8-
providerName="SQLite.Data.SQLite"
8+
providerName="System.Data.SQLite"
99
xdt:Transform="InsertIfMissing"
1010
xdt:Locator="Match(name)" />
1111
</connectionStrings>

content/App.config.uninstall.xdt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<add
55
name="Databasic.Example.SQLite"
66
connectionString="Data Source=.\sqlite.db;Version=3;Password=PASSWORD;"
7-
providerName="SQLite.Data.SQLite"
7+
providerName="System.Data.SQLite"
88
xdt:Transform="Remove"
99
xdt:Locator="Match(name)" />
1010
</connectionStrings>

content/Web.config.install.xdt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<add
66
name="Databasic.Example.SQLite"
77
connectionString="Data Source=.\sqlite.db;Version=3;Password=PASSWORD;"
8-
providerName="SQLite.Data.SQLite"
8+
providerName="System.Data.SQLite"
99
xdt:Transform="InsertIfMissing"
1010
xdt:Locator="Match(name)" />
1111
</connectionStrings>

content/Web.config.uninstall.xdt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<add
55
name="Databasic.Example.SQLite"
66
connectionString="Data Source=.\sqlite.db;Version=3;Password=PASSWORD;"
7-
providerName="SQLite.Data.SQLite"
7+
providerName="System.Data.SQLite"
88
xdt:Transform="Remove"
99
xdt:Locator="Match(name)" />
1010
</connectionStrings>

0 commit comments

Comments
 (0)