Skip to content

Commit a160bbd

Browse files
committed
release 1.2.8
1 parent 5c84f0f commit a160bbd

File tree

6 files changed

+165
-146
lines changed

6 files changed

+165
-146
lines changed

Databasic.MsSql.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.MsSql</id>
5-
<version>1.2.6.0</version>
5+
<version>1.2.8.0</version>
66
<title>Databasic - Microsoft SQL Server</title>
77
<authors>Tom Flidr</authors>
88
<owners>Tom Flidr</owners>
@@ -17,7 +17,7 @@
1717
<copyright>Copyright © 2017</copyright>
1818
<tags>microsoft sql mssql tsql database query command select insert update delete pure sql dml tool utility library</tags>
1919
<dependencies>
20-
<dependency id="Databasic.Core" version="1.2.4.0" />
20+
<dependency id="Databasic.Core" version="1.2.8.0" />
2121
</dependencies>
2222
<frameworkAssemblies>
2323
<frameworkAssembly assemblyName="System.Core" />

Databasic.MsSql.vbproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
<PropertyGroup>
4343
<OptionInfer>On</OptionInfer>
4444
</PropertyGroup>
45+
<PropertyGroup>
46+
<SignAssembly>true</SignAssembly>
47+
</PropertyGroup>
48+
<PropertyGroup>
49+
<AssemblyOriginatorKeyFile>Tom Flidr - .NET.pfx</AssemblyOriginatorKeyFile>
50+
</PropertyGroup>
4551
<ItemGroup>
4652
<Reference Include="System" />
4753
<Reference Include="System.Data" />
@@ -103,6 +109,7 @@
103109
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
104110
</None>
105111
<None Include="packages.config" />
112+
<None Include="Tom Flidr - .NET.pfx" />
106113
<None Include="_CreateNewNuGetPackage\Config.ps1" />
107114
<None Include="_CreateNewNuGetPackage\DoNotModify\CreateNuGetPackage.ps1" />
108115
<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: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Public Class ProviderResource
1+
Public Class ProviderResource
22
Inherits Databasic.ProviderResource
33

44
Public Overrides Function GetTableColumns(table As String, connection As Databasic.Connection) As Dictionary(Of String, Boolean)
@@ -37,51 +37,54 @@
3737
}).ToDictionary(Of String, Boolean)("name")
3838
End Function
3939

40-
Public Overrides Function GetLastInsertedId(ByRef transaction As Databasic.Transaction, Optional ByRef classMetaDescription As MetaDescription = Nothing) As Object
41-
If classMetaDescription.Tables.Length > 0 Then
42-
Return Databasic.Statement.Prepare(
43-
"SELECT IDENT_CURRENT(@table)", transaction
44-
).FetchOne(New With {
45-
.table = classMetaDescription.Tables(0)
46-
}).ToInstance(Of Object)()
47-
Else
48-
Return Databasic.Statement.Prepare(
49-
"SELECT @@IDENTITY", transaction
50-
).FetchOne().ToInstance(Of Object)()
51-
End If
52-
End Function
40+
Public Overrides Function GetLastInsertedId(
41+
ByRef transaction As Databasic.Transaction,
42+
Optional ByRef classMetaDescription As MetaDescription = Nothing
43+
) As Object
44+
If classMetaDescription.Tables.Length > 0 Then
45+
Return Databasic.Statement.Prepare(
46+
"SELECT IDENT_CURRENT(@table)", transaction
47+
).FetchOne(New With {
48+
.table = classMetaDescription.Tables(0)
49+
}).ToInstance(Of Object)()
50+
Else
51+
Return Databasic.Statement.Prepare(
52+
"SELECT @@IDENTITY", transaction
53+
).FetchOne().ToInstance(Of Object)()
54+
End If
55+
End Function
5356

54-
'Public Overrides Function GetAll(
55-
' connection As Databasic.Connection,
56-
' table As String,
57-
' columns As String,
58-
' Optional offset As Int64? = Nothing,
59-
' Optional limit As Int64? = Nothing,
60-
' Optional orderByStatement As String = ""
61-
') As Databasic.Statement
62-
' Dim sql = $"SELECT {columns} FROM {table}"
63-
' offset = If(offset, 0)
64-
' limit = If(limit, 0)
65-
' If limit > 0 Then
66-
' If connection.ProviderVersion.Major < 12 Then
67-
' sql = $"SELECT {If(limit > 0, "TOP " + limit, "")} ____src.*
68-
' INTO #result
69-
' FROM (
70-
' SELECT *, ROW_NUMBER() OVER (ORDER BY {orderByStatement}) AS ____rowNumber
71-
' FROM {table}
72-
' ) AS ____src
73-
' WHERE ____src.____rowNumber > {offset}
74-
' ORDER BY {orderByStatement}
75-
' ALTER TABLE #result
76-
' DROP COLUMN ____rowNumber
77-
' SELECT * FROM #result
78-
' DROP TABLE #result"
79-
' Else
80-
' sql += $" ORDER BY {orderByStatement} OFFSET {offset} ROWS"
81-
' If limit > 0 Then sql += $" FETCH NEXT {limit} ROWS ONLY"
82-
' End If
83-
' End If
84-
' Return Databasic.Statement.Prepare(sql, connection).FetchAll()
85-
'End Function
57+
'Public Overrides Function GetAll(
58+
' connection As Databasic.Connection,
59+
' table As String,
60+
' columns As String,
61+
' Optional offset As Int64? = Nothing,
62+
' Optional limit As Int64? = Nothing,
63+
' Optional orderByStatement As String = ""
64+
') As Databasic.Statement
65+
' Dim sql = $"SELECT {columns} FROM {table}"
66+
' offset = If(offset, 0)
67+
' limit = If(limit, 0)
68+
' If limit > 0 Then
69+
' If connection.ProviderVersion.Major < 12 Then
70+
' sql = $"SELECT {If(limit > 0, "TOP " + limit, "")} ____src.*
71+
' INTO #result
72+
' FROM (
73+
' SELECT *, ROW_NUMBER() OVER (ORDER BY {orderByStatement}) AS ____rowNumber
74+
' FROM {table}
75+
' ) AS ____src
76+
' WHERE ____src.____rowNumber > {offset}
77+
' ORDER BY {orderByStatement}
78+
' ALTER TABLE #result
79+
' DROP COLUMN ____rowNumber
80+
' SELECT * FROM #result
81+
' DROP TABLE #result"
82+
' Else
83+
' sql += $" ORDER BY {orderByStatement} OFFSET {offset} ROWS"
84+
' If limit > 0 Then sql += $" FETCH NEXT {limit} ROWS ONLY"
85+
' End If
86+
' End If
87+
' Return Databasic.Statement.Prepare(sql, connection).FetchAll()
88+
'End Function
8689

8790
End Class

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Databasic - Microsoft SQL Server
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: 104 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,111 @@
1-
Imports System.ComponentModel
1+
Imports System.ComponentModel
22
Imports System.Data.Common
33
Imports System.Data.SqlClient
44

55
Public Class Statement
6-
Inherits Databasic.Statement
7-
8-
9-
10-
11-
12-
13-
''' <summary>
14-
''' Currently prepared and executed Microsoft SQL command.
15-
''' </summary>
16-
Public Overrides Property Command As DbCommand
17-
Get
18-
Return Me._cmd
19-
End Get
20-
Set(value As DbCommand)
21-
Me._cmd = value
22-
End Set
23-
End Property
24-
Private _cmd As SqlCommand
25-
''' <summary>
26-
''' Currently executed Microsoft SQL data reader from Microsoft SQL command.
27-
''' </summary>
28-
Public Overrides Property Reader As DbDataReader
29-
Get
30-
Return Me._reader
31-
End Get
32-
Set(value As DbDataReader)
33-
Me._reader = value
34-
End Set
35-
End Property
36-
Private _reader As SqlDataReader
37-
38-
39-
40-
41-
42-
43-
44-
45-
''' <summary>
46-
''' Empty SQL statement constructor.
47-
''' </summary>
48-
''' <param name="sql">SQL statement code.</param>
49-
''' <param name="connection">Connection instance.</param>
50-
Public Sub New(sql As String, connection As SqlConnection)
51-
MyBase.New(sql, connection)
52-
Me._cmd = New SqlCommand(sql, connection)
53-
Me._cmd.Prepare()
54-
End Sub
55-
''' <summary>
56-
''' Empty SQL statement constructor.
57-
''' </summary>
58-
''' <param name="sql">SQL statement code.</param>
59-
''' <param name="transaction">SQL transaction instance with connection instance inside.</param>
60-
Public Sub New(sql As String, transaction As SqlTransaction)
61-
MyBase.New(sql, transaction)
62-
Me._cmd = New SqlCommand(sql, transaction.Connection, transaction)
63-
Me._cmd.Prepare()
64-
End Sub
65-
66-
67-
68-
69-
70-
''' <summary>
71-
''' Set up all sql params into internal Command instance.
72-
''' </summary>
73-
''' <param name="sqlParams">Anonymous object with named keys as Microsoft SQL statement params without any '@' chars in object keys.</param>
74-
Protected Overrides Sub addParamsWithValue(sqlParams As Object)
75-
If (Not sqlParams Is Nothing) Then
76-
Dim sqlParamValue As Object
77-
For Each prop As PropertyDescriptor In TypeDescriptor.GetProperties(sqlParams)
78-
sqlParamValue = prop.GetValue(sqlParams)
79-
Me._cmd.Parameters.AddWithValue(
80-
prop.Name,
81-
If((sqlParamValue Is Nothing), DBNull.Value, sqlParamValue)
82-
)
83-
Next
84-
End If
85-
End Sub
86-
''' <summary>
87-
''' Set up all sql params into internal Command instance.
88-
''' </summary>
89-
''' <param name="sqlParams">Dictionary with named keys as Microsoft SQL statement params without any '@' chars in dictionary keys.</param>
90-
Protected Overrides Sub addParamsWithValue(sqlParams As Dictionary(Of String, Object))
91-
If (Not sqlParams Is Nothing) Then
92-
For Each pair As KeyValuePair(Of String, Object) In sqlParams
93-
Me._cmd.Parameters.AddWithValue(
94-
pair.Key,
95-
If((pair.Value Is Nothing), DBNull.Value, pair.Value)
96-
)
97-
Next
98-
End If
99-
End Sub
6+
Inherits Databasic.Statement
7+
8+
9+
10+
11+
12+
13+
''' <summary>
14+
''' Currently prepared and executed Microsoft SQL command.
15+
''' </summary>
16+
Public Overrides Property Command As DbCommand
17+
Get
18+
Return Me._cmd
19+
End Get
20+
Set(value As DbCommand)
21+
Me._cmd = value
22+
End Set
23+
End Property
24+
Private _cmd As SqlCommand
25+
''' <summary>
26+
''' Currently executed Microsoft SQL data reader from Microsoft SQL command.
27+
''' </summary>
28+
Public Overrides Property Reader As DbDataReader
29+
Get
30+
Return Me._reader
31+
End Get
32+
Set(value As DbDataReader)
33+
Me._reader = value
34+
End Set
35+
End Property
36+
Private _reader As SqlDataReader
37+
38+
39+
40+
41+
42+
43+
44+
45+
''' <summary>
46+
''' Empty SQL statement constructor.
47+
''' </summary>
48+
''' <param name="sql">SQL statement code.</param>
49+
''' <param name="connection">Connection instance.</param>
50+
Public Sub New(sql As String, connection As SqlConnection)
51+
MyBase.New(sql, connection)
52+
Me._cmd = New SqlCommand(sql, connection)
53+
Me._cmd.Prepare()
54+
End Sub
55+
''' <summary>
56+
''' Empty SQL statement constructor.
57+
''' </summary>
58+
''' <param name="sql">SQL statement code.</param>
59+
''' <param name="transaction">SQL transaction instance with connection instance inside.</param>
60+
Public Sub New(sql As String, transaction As SqlTransaction)
61+
MyBase.New(sql, transaction)
62+
Me._cmd = New SqlCommand(sql, transaction.Connection, transaction)
63+
Me._cmd.Prepare()
64+
End Sub
65+
66+
67+
68+
69+
70+
''' <summary>
71+
''' Set up all sql params into internal Command instance.
72+
''' </summary>
73+
''' <param name="sqlParams">Anonymous object with named keys as Microsoft SQL statement params without any '@' chars in object keys.</param>
74+
Protected Overrides Sub addParamsWithValue(sqlParams As Object)
75+
If (Not sqlParams Is Nothing) Then
76+
Dim sqlParamValue As Object
77+
For Each prop As PropertyDescriptor In TypeDescriptor.GetProperties(sqlParams)
78+
sqlParamValue = prop.GetValue(sqlParams)
79+
If (sqlParamValue Is Nothing) Then
80+
sqlParamValue = DBNull.Value
81+
Else
82+
sqlParamValue = Me.getPossibleUnderlyingEnumValue(sqlParamValue)
83+
End If
84+
Me._cmd.Parameters.AddWithValue(
85+
prop.Name, sqlParamValue
86+
)
87+
Next
88+
End If
89+
End Sub
90+
''' <summary>
91+
''' Set up all sql params into internal Command instance.
92+
''' </summary>
93+
''' <param name="sqlParams">Dictionary with named keys as Microsoft SQL statement params without any '@' chars in dictionary keys.</param>
94+
Protected Overrides Sub addParamsWithValue(sqlParams As Dictionary(Of String, Object))
95+
Dim sqlParamValue As Object
96+
If (Not sqlParams Is Nothing) Then
97+
For Each pair As KeyValuePair(Of String, Object) In sqlParams
98+
If (pair.Value Is Nothing) Then
99+
sqlParamValue = DBNull.Value
100+
Else
101+
sqlParamValue = Me.getPossibleUnderlyingEnumValue(pair.Value)
102+
End If
103+
Me._cmd.Parameters.AddWithValue(
104+
pair.Key, sqlParamValue
105+
)
106+
Next
107+
End If
108+
End Sub
100109

101110

102111

0 commit comments

Comments
 (0)