Skip to content

Commit b537938

Browse files
committed
prerelease 1.1
1 parent 81d5823 commit b537938

10 files changed

+122
-139
lines changed

Connection.vb

Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,28 @@
22
Imports System.Data.SqlClient
33

44
Public Class Connection
5-
Inherits Databasic.Connection
6-
7-
Public Shared Shadows ClientName As String = "System.Data.SqlClient"
8-
9-
Public Overrides Property Provider As DbConnection
10-
Get
11-
Return Me._provider
12-
End Get
13-
Set(value As DbConnection)
14-
Me._provider = value
15-
End Set
16-
End Property
17-
Private _provider As SqlConnection
18-
19-
Public Overrides ReadOnly Property ProviderVersion As Version
20-
Get
21-
If Me._providerVersion Is Nothing Then
22-
Me._providerVersion = New Version(Me.Provider.ServerVersion)
23-
End If
24-
Return Me._providerVersion
25-
End Get
26-
End Property
27-
Private _providerVersion As Version = Nothing
28-
29-
Public Overrides Property StatementType As System.Type
30-
Get
31-
Return Me._statementType
32-
End Get
33-
Set(value As System.Type)
34-
Me._statementType = value
35-
End Set
36-
End Property
37-
Private _statementType As System.Type = GetType(Statement)
38-
39-
Public Overrides Property ResourceType As System.Type
40-
Get
41-
Return Me._resourceType
42-
End Get
43-
Set(value As System.Type)
44-
Me._resourceType = value
45-
End Set
46-
End Property
47-
Private _resourceType As System.Type = GetType(Resource)
48-
49-
Public Overrides Sub Open(dsn As String)
50-
Me._provider = New SqlConnection(dsn)
51-
Me._provider.Open()
52-
AddHandler Me._provider.InfoMessage, AddressOf Connection.errorHandler
53-
End Sub
54-
55-
Public Overrides Function CreateAndBeginTransaction(Optional transactionName As String = "", Optional isolationLevel As IsolationLevel = IsolationLevel.Unspecified) As Databasic.Transaction
5+
Inherits Databasic.Connection
6+
7+
Public Overrides ReadOnly Property Provider As DbConnection
8+
Get
9+
Return Me._provider
10+
End Get
11+
End Property
12+
Private _provider As SqlConnection
13+
14+
Public Overrides ReadOnly Property ProviderResource As System.Type = GetType(ProviderResource)
15+
16+
Public Overrides ReadOnly Property ClientName As String = "System.Data.SqlClient"
17+
18+
Public Overrides ReadOnly Property Statement As System.Type = GetType(Statement)
19+
20+
Public Overrides Sub Open(dsn As String)
21+
Me._provider = New SqlConnection(dsn)
22+
Me._provider.Open()
23+
AddHandler Me._provider.InfoMessage, AddressOf Connection.errorHandler
24+
End Sub
25+
26+
Public Overrides Function CreateAndBeginTransaction(Optional transactionName As String = "", Optional isolationLevel As IsolationLevel = IsolationLevel.Unspecified) As Databasic.Transaction
5627
Return New Transaction() With {
5728
.ConnectionWrapper = Me,
5829
.Instance = Me._provider.BeginTransaction(isolationLevel, transactionName.Substring(0, Math.Min(transactionName.Length - 1, 32)))

Databasic.MsSql.nuspec

Lines changed: 5 additions & 8 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.0.0.0</version>
5+
<version>1.1.0.0</version>
66
<title>Databasic - Microsoft SQL Package</title>
77
<authors>Tom Flidr</authors>
88
<owners>Tom Flidr</owners>
@@ -12,18 +12,15 @@
1212
<language>en-US</language>
1313
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1414
<description>
15-
Databasic - C#/VB.NET database utility
16-
- focusing on queries primarily based on pure SQL commands, no linq transations
17-
- arranging data into primitive types, typed active record classes, collections and more
18-
- allowing to run any nonselect queries
15+
C#/VB.NET database utility to write pure Microsoft SQL queries and load data into environment variables and instances.
1916
</description>
2017
<copyright>Copyright © 2017</copyright>
2118
<tags>sql database select selecting query queries commands mssql tool utility</tags>
2219
<dependencies>
23-
<dependency id="System" version="4.0.0.0" />
20+
<!--dependency id="System" version="4.0.0.0" />
2421
<dependency id="System.Core" version="4.0.0.0" />
25-
<dependency id="System.Data" version="4.0.0.0" />
26-
<dependency id="Databasic" version="1.0.0.0" />
22+
<dependency id="System.Data" version="4.0.0.0" /-->
23+
<dependency id="Databasic.Core" version="1.1.0.0" />
2724
</dependencies>
2825
<releaseNotes>https://github.com/databasic-net/databasic/releases</releaseNotes>
2926
</metadata>

Databasic.MsSql.vbproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
<DependentUpon>Settings.settings</DependentUpon>
7575
<DesignTimeSharedInput>True</DesignTimeSharedInput>
7676
</Compile>
77-
<Compile Include="Resource.vb" />
77+
<Compile Include="ProviderResource.vb" />
7878
<Compile Include="Statement.vb" />
7979
<Compile Include="Transaction.vb" />
8080
</ItemGroup>

My Project/AssemblyInfo.vb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Imports System.Runtime.InteropServices
2121
<Assembly: ComVisible(False)>
2222

2323
'The following GUID is for the ID of the typelib if this project is exposed to COM
24-
<Assembly: Guid("d7594b0e-a7ac-4a77-a22c-af8d73894446")>
24+
<Assembly: Guid("d7594b0e-a7ac-4a77-a22c-af8d73894446")>
2525

2626
' Version information for an assembly consists of the following four values:
2727
'
@@ -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.0.0.0")>
38-
<Assembly: AssemblyFileVersion("1.0.0.0")>
37+
<Assembly: AssemblyVersion("1.1.0.0")>
38+
<Assembly: AssemblyFileVersion("1.1.0.0")>

ProviderResource.vb

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
Public Class ProviderResource
2+
Inherits Databasic.ProviderResource
3+
4+
Public Overrides Function GetTableColumns(table As String, connection As Databasic.Connection) As Dictionary(Of String, Boolean)
5+
Dim schema = "dbo"
6+
Dim dotPos = table.IndexOf("."c) ' ignore (screw) here all tables with dot contained in name, only realy dummy developers can use that form...:-(
7+
If dotPos > -1 Then
8+
schema = table.Substring(0, dotPos)
9+
table = table.Substring(dotPos + 1)
10+
End If
11+
Return Databasic.Statement.Prepare("
12+
SELECT
13+
c.is_nullable,
14+
c.name
15+
FROM
16+
sys.columns AS c
17+
WHERE
18+
c.object_id = (
19+
SELECT
20+
o.object_id
21+
FROM
22+
sys.objects AS o
23+
WHERE
24+
o.name = @table AND
25+
o.schema_id = (
26+
SELECT s.schema_id
27+
FROM sys.schemas AS s
28+
WHERE s.name = @schema
29+
)
30+
)
31+
ORDER BY
32+
c.column_id
33+
", connection
34+
).FetchAll(New With {
35+
.schema = schema,
36+
.table = table
37+
}).ToDictionary(Of String, Boolean)("name")
38+
End Function
39+
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
53+
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
86+
87+
End Class

Resource.vb

Lines changed: 0 additions & 72 deletions
This file was deleted.

content/App.config.install.xdt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<clear xdt:Transform="InsertIfMissing" />
55
<add
66
name="Databasic.Example.MsSql"
7-
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DATABASE_NAME;Persist Security Info=True;User ID=USER_NAME;Password=PASSWORD"
7+
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DATABASE;User ID=USER_NAME;Password=PASSWORD;Persist Security Info=True;"
88
providerName="System.Data.SqlClient"
99
xdt:Transform="InsertIfMissing"
1010
xdt:Locator="Match(name)" />

content/App.config.uninstall.xdt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<connectionStrings>
44
<add
55
name="Databasic.Example.MsSql"
6-
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DATABASE_NAME;Persist Security Info=True;User ID=USER_NAME;Password=PASSWORD"
6+
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DATABASE;User ID=USER_NAME;Password=PASSWORD;Persist Security Info=True;"
77
providerName="System.Data.SqlClient"
88
xdt:Transform="Remove"
99
xdt:Locator="Match(name)" />

content/Web.config.install.xdt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<clear xdt:Transform="InsertIfMissing" />
55
<add
66
name="Databasic.Example.MsSql"
7-
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DATABASE_NAME;Persist Security Info=True;User ID=USER_NAME;Password=PASSWORD"
7+
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DATABASE;User ID=USER_NAME;Password=PASSWORD;Persist Security Info=True;"
88
providerName="System.Data.SqlClient"
99
xdt:Transform="InsertIfMissing"
1010
xdt:Locator="Match(name)" />

content/Web.config.uninstall.xdt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<connectionStrings>
44
<add
55
name="Databasic.Example.MsSql"
6-
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DATABASE_NAME;Persist Security Info=True;User ID=USER_NAME;Password=PASSWORD"
6+
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DATABASE;User ID=USER_NAME;Password=PASSWORD;Persist Security Info=True;"
77
providerName="System.Data.SqlClient"
88
xdt:Transform="Remove"
99
xdt:Locator="Match(name)" />

0 commit comments

Comments
 (0)