Skip to content

Commit 2d09057

Browse files
author
ActiveDbSoft
committed
3.1.1
1 parent 8ff4800 commit 2d09057

File tree

138 files changed

+3017
-56882
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+3017
-56882
lines changed

CustomStorage/Controllers/HomeController.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ public class HomeController : Controller
88
// GET
99
public ActionResult Index()
1010
{
11-
// We've redefined the QueryBuilderStore.Provider object to be of QueryBuilderSqliteStoreProvider class in the Global.asax.cs file.
12-
// The implementation of Get method in this provider gets _OR_creates_new_ QueryBuilder object.
13-
// The initialization of the QueryBuilder object is also internally made by the QueryBuilderSqliteStoreProvider.
14-
var qb = QueryBuilderStore.Get();
15-
return View(qb);
11+
return View();
1612
}
1713
}
1814
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using System;
2+
using System.Data;
3+
using System.Linq;
4+
using System.Net;
5+
using System.Web.Mvc;
6+
using ActiveQueryBuilder.Core.QueryTransformer;
7+
using ActiveQueryBuilder.Web.Server;
8+
using CustomStorage.Helpers;
9+
10+
namespace CustomStorage.Controllers
11+
{
12+
public class QueryResultsDemoController : Controller
13+
{
14+
private string instanceId = "QueryResults";
15+
16+
public ActionResult Index()
17+
{
18+
return View();
19+
}
20+
21+
public ActionResult GetData(GridModel m)
22+
{
23+
var qt = QueryTransformerStore.Get(instanceId);
24+
25+
qt.Skip((m.Pagenum * m.Pagesize).ToString());
26+
qt.Take(m.Pagesize == 0 ? "" : m.Pagesize.ToString());
27+
28+
if (!string.IsNullOrEmpty(m.Sortdatafield))
29+
{
30+
qt.Sortings.Clear();
31+
32+
if (!string.IsNullOrEmpty(m.Sortorder))
33+
{
34+
var c = qt.Columns.FindColumnByResultName(m.Sortdatafield);
35+
36+
if (c != null)
37+
qt.OrderBy(c, m.Sortorder.ToLower() == "asc");
38+
}
39+
}
40+
41+
return GetData(qt, m.Params);
42+
}
43+
44+
private ActionResult GetData(QueryTransformer qt, Param[] _params)
45+
{
46+
var conn = qt.Query.SQLContext.MetadataProvider.Connection;
47+
var sql = qt.SQL;
48+
49+
if (_params != null)
50+
foreach (var p in _params)
51+
p.DataType = qt.Query.QueryParameters.First(qp => qp.FullName == p.Name).DataType;
52+
53+
try
54+
{
55+
var data = DataBaseHelper.GetData(conn, sql, _params);
56+
return Json(data, JsonRequestBehavior.AllowGet);
57+
}
58+
catch (Exception e)
59+
{
60+
return new HttpStatusCodeResult((int)HttpStatusCode.BadRequest, e.Message);
61+
}
62+
}
63+
64+
public void LoadQuery(string query)
65+
{
66+
var qb = QueryBuilderStore.Get(instanceId);
67+
68+
if (query == "artist")
69+
qb.SQL = "Select artists.ArtistId, artists.Name From artists";
70+
else
71+
qb.SQL = "Select tracks.TrackId, tracks.Name From tracks";
72+
73+
QueryBuilderStore.Put(qb);
74+
}
75+
}
76+
77+
public class GridModel
78+
{
79+
public int Pagenum { get; set; }
80+
public int Pagesize { get; set; }
81+
public string Sortdatafield { get; set; }
82+
public string Sortorder { get; set; }
83+
public Param[] Params { get; set; }
84+
}
85+
86+
public class Param
87+
{
88+
public string Name { get; set; }
89+
public string Value { get; set; }
90+
public DbType DataType { get; set; }
91+
}
92+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Web.Mvc;
2+
using ActiveQueryBuilder.Web.Server;
3+
4+
namespace CustomStorage.Controllers
5+
{
6+
public class SimpleDemoController : Controller
7+
{
8+
// GET
9+
public ActionResult Index()
10+
{
11+
// We've redefined the QueryBuilderStore.Provider object to be of QueryBuilderSqliteStoreProvider class in the Global.asax.cs file.
12+
// The implementation of Get method in this provider gets _OR_creates_new_ QueryBuilder object.
13+
// The initialization of the QueryBuilder object is also internally made by the QueryBuilderSqliteStoreProvider.
14+
var qb = QueryBuilderStore.Get();
15+
return View(qb);
16+
}
17+
}
18+
}

CustomStorage/CustomStorage.csproj

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
@@ -50,8 +50,8 @@
5050
<Reference Include="Microsoft.CSharp" />
5151
<Reference Include="System" />
5252
<Reference Include="System.Data" />
53-
<Reference Include="System.Data.SQLite, Version=1.0.107.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
54-
<HintPath>..\packages\System.Data.SQLite.Core.1.0.107.0\lib\net45\System.Data.SQLite.dll</HintPath>
53+
<Reference Include="System.Data.SQLite, Version=1.0.108.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
54+
<HintPath>..\packages\System.Data.SQLite.Core.1.0.108.0\lib\net45\System.Data.SQLite.dll</HintPath>
5555
</Reference>
5656
<Reference Include="System.Drawing" />
5757
<Reference Include="System.Web.DynamicData" />
@@ -122,7 +122,9 @@
122122
<Compile Include="App_Start\BundleConfig.cs" />
123123
<Compile Include="App_Start\FilterConfig.cs" />
124124
<Compile Include="App_Start\RouteConfig.cs" />
125+
<Compile Include="Controllers\SimpleDemoController.cs" />
125126
<Compile Include="Controllers\HomeController.cs" />
127+
<Compile Include="Controllers\QueryResultsDemoController.cs" />
126128
<Compile Include="Global.asax.cs">
127129
<DependentUpon>Global.asax</DependentUpon>
128130
</Compile>
@@ -191,8 +193,10 @@
191193
<Content Include="Views\_ViewStart.cshtml" />
192194
<Content Include="Views\Shared\Error.cshtml" />
193195
<Content Include="Views\Shared\_Layout.cshtml" />
194-
<Content Include="Views\Home\Index.cshtml" />
196+
<Content Include="Views\SimpleDemo\Index.cshtml" />
195197
<Content Include="Scripts\jquery-1.10.2.min.map" />
198+
<Content Include="Views\QueryResultsDemo\Index.cshtml" />
199+
<Content Include="Views\Home\Index.cshtml" />
196200
</ItemGroup>
197201
<ItemGroup>
198202
<Folder Include="App_Data\" />
@@ -207,20 +211,20 @@
207211
</ItemGroup>
208212
<ItemGroup>
209213
<Reference Include="ActiveQueryBuilder.SQLiteMetadataProvider">
210-
<HintPath>..\packages\ActiveQueryBuilder.SQLiteMetadataProvider.3.4.5.1082\lib\net\ActiveQueryBuilder.SQLiteMetadataProvider.dll</HintPath>
211-
</Reference>
214+
<HintPath>..\packages\ActiveQueryBuilder.SQLiteMetadataProvider.3.4.7.1084\lib\net\ActiveQueryBuilder.SQLiteMetadataProvider.dll</HintPath>
215+
</Reference>
212216
<Reference Include="ActiveQueryBuilder.Core">
213-
<HintPath>..\packages\ActiveQueryBuilder.Core.3.4.5.1082\lib\net\ActiveQueryBuilder.Core.dll</HintPath>
214-
</Reference>
217+
<HintPath>..\packages\ActiveQueryBuilder.Core.3.4.7.1084\lib\net\ActiveQueryBuilder.Core.dll</HintPath>
218+
</Reference>
215219
<Reference Include="ActiveQueryBuilder.View">
216-
<HintPath>..\packages\ActiveQueryBuilder.Web.MVC.3.1.0\lib\ActiveQueryBuilder.View.dll</HintPath>
217-
</Reference>
220+
<HintPath>..\packages\ActiveQueryBuilder.Web.MVC.3.1.1\lib\net\ActiveQueryBuilder.View.dll</HintPath>
221+
</Reference>
218222
<Reference Include="ActiveQueryBuilder.Web.MVC">
219-
<HintPath>..\packages\ActiveQueryBuilder.Web.MVC.3.1.0\lib\ActiveQueryBuilder.Web.MVC.dll</HintPath>
220-
</Reference>
223+
<HintPath>..\packages\ActiveQueryBuilder.Web.MVC.3.1.1\lib\net\ActiveQueryBuilder.Web.MVC.dll</HintPath>
224+
</Reference>
221225
<Reference Include="ActiveQueryBuilder.Web.Server">
222-
<HintPath>..\packages\ActiveQueryBuilder.Web.MVC.3.1.0\lib\ActiveQueryBuilder.Web.Server.dll</HintPath>
223-
</Reference>
226+
<HintPath>..\packages\ActiveQueryBuilder.Web.MVC.3.1.1\lib\net\ActiveQueryBuilder.Web.Server.dll</HintPath>
227+
</Reference>
224228
</ItemGroup>
225229
<PropertyGroup>
226230
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
@@ -251,4 +255,11 @@
251255
</VisualStudio>
252256
</ProjectExtensions>
253257
<Import Project="..\packages\System.Data.SQLite.Core.1.0.106.0\build\net45\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.106.0\build\net45\System.Data.SQLite.Core.targets')" />
258+
<Import Project="..\packages\System.Data.SQLite.Core.1.0.108.0\build\net45\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.108.0\build\net45\System.Data.SQLite.Core.targets')" />
259+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
260+
<PropertyGroup>
261+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
262+
</PropertyGroup>
263+
<Error Condition="!Exists('..\packages\System.Data.SQLite.Core.1.0.108.0\build\net45\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.108.0\build\net45\System.Data.SQLite.Core.targets'))" />
264+
</Target>
254265
</Project>

CustomStorage/Global.asax.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ protected void Application_Start()
2121

2222
// Redefine the QueryBuilderStore.Provider object to be an instance of the QueryBuilderSqliteStoreProvider class
2323
QueryBuilderStore.Provider = new QueryBuilderSqliteStoreProvider();
24+
// Redefine the QueryTransformerStore.Provider object to be an instance of the QueryTransformerSqliteStoreProvider class
25+
QueryTransformerStore.Provider = new QueryTransformerSqliteStoreProvider();
2426
}
2527
}
2628

CustomStorage/Helpers/DataBaseHelper.cs

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
using System.Configuration;
1+
using System.Collections.Generic;
2+
using System.Configuration;
23
using System.Data;
34
using System.Data.SQLite;
45
using System.IO;
56
using System.Web;
7+
using CustomStorage.Controllers;
68

79
namespace CustomStorage.Helpers
810
{
@@ -11,6 +13,72 @@ namespace CustomStorage.Helpers
1113
/// </summary>
1214
public static class DataBaseHelper
1315
{
16+
/// <summary>
17+
/// Executes a query and returns the result data as a list of records. Each record is represented as a list of field name-value pairs.
18+
/// </summary>
19+
/// <param name="conn">The DB connection object.</param>
20+
/// <param name="sql">The SQL query text.</param>
21+
/// <returns>List of records.</returns>
22+
public static List<Dictionary<string, object>> GetData(IDbConnection conn, string sql, Param[] parameters)
23+
{
24+
IDbCommand cmd = conn.CreateCommand();
25+
cmd.CommandText = sql;
26+
27+
if (string.IsNullOrEmpty(sql))
28+
return new List<Dictionary<string, object>>();
29+
30+
if (parameters != null)
31+
AddParameters(cmd, parameters);
32+
33+
try
34+
{
35+
if (conn.State != ConnectionState.Open)
36+
conn.Open();
37+
38+
IDataReader reader = cmd.ExecuteReader();
39+
return ConvertToList(reader);
40+
}
41+
finally
42+
{
43+
conn.Close();
44+
}
45+
}
46+
47+
private static void AddParameters(IDbCommand cmd, Param[] parameters)
48+
{
49+
foreach (var p in parameters)
50+
{
51+
var param = cmd.CreateParameter();
52+
param.DbType = p.DataType;
53+
param.ParameterName = p.Name;
54+
param.Value = p.Value;
55+
56+
cmd.Parameters.Add(param);
57+
}
58+
}
59+
60+
/// <summary>
61+
/// Saves data from IDataReader to the list. Each record is represented as a list of field name-value pairs.
62+
/// </summary>
63+
/// <param name="reader">The Data Reader object.</param>
64+
/// <returns>List of records.</returns>
65+
private static List<Dictionary<string, object>> ConvertToList(IDataReader reader)
66+
{
67+
var result = new List<Dictionary<string, object>>();
68+
69+
while (reader.Read())
70+
{
71+
var row = new Dictionary<string, object>();
72+
73+
for (int i = 0; i < reader.FieldCount; i++)
74+
row.Add(reader.GetName(i), reader[i]);
75+
76+
result.Add(row);
77+
}
78+
79+
return result;
80+
}
81+
1482
/// <summary>
1583
/// Creates DBConnection object for SQLite database.
1684
/// </summary>

0 commit comments

Comments
 (0)