Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sqlmodule #9

Merged
merged 2 commits into from
Oct 1, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified DNN Platform/Library/Data/DataProvider.cs
Binary file not shown.
17 changes: 14 additions & 3 deletions DNN Platform/Library/Data/SqlDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,25 @@ private string ExecuteScriptInternal(string connectionString, string script)
}

private IDataReader ExecuteSQLInternal(string connectionString, string sql)
{
string errorMessage;
return ExecuteSQLInternal(connectionString, sql, out errorMessage);
}
private IDataReader ExecuteSQLInternal(string connectionString, string sql, out string errorMessage)
{
try
{
sql = DataUtil.ReplaceTokens(sql);
errorMessage = "";
return PetaPocoHelper.ExecuteReader(connectionString, CommandType.Text, sql);
}
catch
catch (Exception ex)
{
//error in SQL query
errorMessage = ex + Environment.NewLine + Environment.NewLine + sql + Environment.NewLine + Environment.NewLine;
return null;
}
}

private string GetConnectionStringUserID()
{
string DBUser = "public";
Expand Down Expand Up @@ -380,7 +386,12 @@ public override IDataReader ExecuteSQL(string sql)

public override IDataReader ExecuteSQLTemp(string connectionString, string sql)
{
return ExecuteSQLInternal(connectionString, sql);
string errorMessage;
return ExecuteSQLTemp(connectionString, sql, out errorMessage);
}
public override IDataReader ExecuteSQLTemp(string connectionString, string sql, out string errorMessage)
{
return ExecuteSQLInternal(connectionString, sql, out errorMessage);
}


Expand Down
2 changes: 2 additions & 0 deletions DNN Platform/Library/DotNetNuke.Library.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@
<Compile Include="Framework\ServicesFramework.cs" />
<Compile Include="Framework\ServicesFrameworkImpl.cs" />
<Compile Include="Framework\ServicesFrameworkInternal.cs" />
<Compile Include="Modules\SQL\Components\SqlQueryController.cs" />
<Compile Include="Modules\SQL\Components\SqlQuery.cs" />
<Compile Include="Security\Membership\AspNetMembershipProvider.cs" />
<Compile Include="Security\Permissions\CorePermissionProvider.cs" />
<Compile Include="Security\Profile\DNNProfileProvider.cs" />
Expand Down
54 changes: 54 additions & 0 deletions DNN Platform/Library/Modules/SQL/Components/SqlQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#region Copyright
//
// DotNetNuke� - http://www.dotnetnuke.com
// Copyright (c) 2002-2013
// by DotNetNuke Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
#region Usings

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Xml;

using DotNetNuke.Common;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.ComponentModel.DataAnnotations;
using DotNetNuke.Entities;

#endregion

namespace DotNetNuke.Modules.SQL.Components
{
[TableName("SQLQueries")]
[PrimaryKey("QueryId")]
public partial class SqlQuery
{
public int QueryId { get; set; }
public string Name { get; set; }
public string Query { get; set; }
public string ConnectionStringName { get; set; }
public int CreatedByUserId { get; set; }
public DateTime CreatedOnDate { get; set; }
public int LastModifiedByUserId { get; set; }
public DateTime LastModifiedOnDate { get; set; }
}
}
100 changes: 100 additions & 0 deletions DNN Platform/Library/Modules/SQL/Components/SqlQueryController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#region Copyright
//
// DotNetNuke® - http://www.dotnetnuke.com
// Copyright (c) 2002-2013
// by DotNetNuke Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion

#region Usings

using System.Collections.Generic;
using DotNetNuke.Data;
using System.Linq;

#endregion

namespace DotNetNuke.Modules.SQL.Components
{
public class SqlQueryController
{
public void AddQuery(SqlQuery query)
{
using (IDataContext ctx = DataContext.Instance())
{
var rep = ctx.GetRepository<SqlQuery>();
rep.Insert(query);
}
}

public void DeleteQuery(SqlQuery query)
{
using (IDataContext ctx = DataContext.Instance())
{
var rep = ctx.GetRepository<SqlQuery>();
rep.Delete(query);
}
}

public IEnumerable<SqlQuery> GetQueries()
{
IEnumerable<SqlQuery> queries;

using (IDataContext ctx = DataContext.Instance())
{
var rep = ctx.GetRepository<SqlQuery>();
queries = rep.Get();
}
return queries;
}

public SqlQuery GetQuery(int id)
{
SqlQuery query;

using (IDataContext ctx = DataContext.Instance())
{
var rep = ctx.GetRepository<SqlQuery>();
query = rep.GetById(id);
}
return query;
}

public SqlQuery GetQuery(string name)
{
List<SqlQuery> queries;
SqlQuery query = null;

using (IDataContext ctx = DataContext.Instance())
{
var rep = ctx.GetRepository<SqlQuery>();
queries = rep.Find("where name = @0", name).ToList();
if (queries != null && queries.Count > 0)
query = queries.ElementAt(0);
}
return query;
}

public void UpdateQuery(SqlQuery query)
{
using (IDataContext ctx = DataContext.Instance())
{
var rep = ctx.GetRepository<SqlQuery>();
rep.Update(query);
}
}
}
}
65 changes: 55 additions & 10 deletions Website/DesktopModules/Admin/SQL/App_LocalResources/SQL.ascx.resx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
<value>Run Script</value>
</data>
<data name="cmdExecute.ToolTip" xml:space="preserve">
<value>can include {directives} and /*comments*/</value>
<value>Can include {directives} and /*comments*/</value>
</data>
<data name="QueryError.Text" xml:space="preserve">
<value>There is an error in your query!</value>
Expand Down Expand Up @@ -157,21 +157,66 @@
<value>The query did not return any data</value>
</data>
<data name="scriptLabel.Text" xml:space="preserve">
<value>Script:</value>
<value>Script</value>
</data>
<data name="scriptLabel.Help" xml:space="preserve">
<value>Enter the SQL you wish to execute.</value>
</data>
<data name="runasLabel.Text" xml:space="preserve">
<value>Run as Script:</value>
</data>
<data name="runasLabel.Help" xml:space="preserve">
<value>Select if the SQL statement does not return a value and only acts on the database to make changes</value>
<value>Enter the SQL you wish to execute. You can use more than one SELECT statement to return multiple result sets.</value>
</data>
<data name="errorLabel.Help" xml:space="preserve">
<value>This is the error returned by SQL server after executing your SQL script.</value>
</data>
<data name="errorLabel.Text" xml:space="preserve">
<value>Error Details:</value>
<value>Error Details</value>
</data>
<data name="CnnStringNotFound.Text" xml:space="preserve">
<value>The query has been loaded but the associated Connection ("{0}") was not found. Default "SiteSqlServer" Connection has been selected instead.</value>
</data>
<data name="Deleted.Text" xml:space="preserve">
<value>The query has been successfully deleted.</value>
</data>
<data name="lblSavedQuery.Help" xml:space="preserve">
<value>Select a presaved query. You can run it as is or modify before executing it</value>
</data>
<data name="lblSavedQuery.Text" xml:space="preserve">
<value>Saved Query:</value>
</data>
<data name="lnkDelete.Text" xml:space="preserve">
<value>Delete Query</value>
</data>
<data name="lnkLoad.Text" xml:space="preserve">
<value>Load Query</value>
</data>
<data name="lnkSaveQuery.Text" xml:space="preserve">
<value>Save Query</value>
</data>
<data name="NewQuery.Text" xml:space="preserve">
<value>&lt; New Query &gt;</value>
</data>
<data name="NoScript.Text" xml:space="preserve">
<value>Please write or load the script you want to run.</value>
</data>
<data name="SaveDialogTitle.Text" xml:space="preserve">
<value>Save Query As...</value>
</data>
<data name="lblName.Help" xml:space="preserve">
<value>Provide a name to identify the saved query.</value>
</data>
<data name="lblName.Text" xml:space="preserve">
<value>Name:</value>
</data>
<data name="lnkSave.Text" xml:space="preserve">
<value>Save</value>
</data>
<data name="NoName.Text" xml:space="preserve">
<value>You have to provide a name for the query</value>
</data>
<data name="Saved.Text" xml:space="preserve">
<value>The query has been successfully saved.</value>
</data>
<data name="CopyToClipboard.Text" xml:space="preserve">
<value>Copy to Clipboard</value>
</data>
<data name="lblNoData.Text" xml:space="preserve">
<value>Your query returned no data.</value>
</data>
</root>
Loading