Skip to main content

Posts

Showing posts with the label EntitySpaces

Calling a custom database function in WHERE part of your entity

I have encountered a need to call a custom database function in WHERE part of the entity using entityspaces(2008.x.x) which does not support Raw SQL Injection Everywhere . I have searched everywhere and posted inquiries in the friendly ES forum but theres no luck. This task can be done easily using stored procedure but I wanted to use ES for I have other filters, join and grouping, all of this are already in place except for the part where I need to call the function. Now LastQuery to the rescue, this property contains nothing until you make the query, so the idea is to call the query making sure that only one or zero record will be return then use the value of LastQuery to construct a new SQL Query/Statement with the datase function in it to be use in our entity custom load. I am not sure if this is a good practice but I works for me. See the code below. ' Make sure we only have one record for this load Dim esqUsers As New UserCollectionQuery("uv") es...

Check if a table exist using EntitySpaces in DotNetNuke

Using esUtility ExecuteScalar method the function(VB.Net) below given the table name will return true if the table exist in the database otherwise it will return false. Public Shared Function TableExist(ByVal tableName As String) As Boolean Dim strSQL As String = "SELECT Count(*) FROM dbo.sysobjects WHERE id = object_id(N'{databaseOwner}[{objectQualifier}" & tableName & "]') AND OBJECTPROPERTY(id, N'IsTable') = 1" strSQL = strSQL.Replace("{databaseOwner}", DotNetNuke.Common.Utilities.Config.GetDataBaseOwner()) strSQL = strSQL.Replace("{objectQualifier}", DotNetNuke.Common.Utilities.Config.GetObjectQualifer()) Dim util As New esUtility() If util.ExecuteScalar(esQueryType.Text, strsql) > 0 Then Return True Else Return False End If End Function