2008.04.22

Install server or ca certificate in Coldfusion or Java Virtual Machine

The other day I was working on a project in ColdFusion where I wanted to connect to a secure web server using CFHttp and do some screen scrapes. The problem I encountered was that the server was using a self issued certificate that therefore did not have a proper certificate chain. ColdFusion simply returned the following error:

I/O Exception: peer not authenticated
coldfusioncerterror

After some detective work.. found out what the problem was and devised an effective solution which I provide you with now…. You will need a couple of free tools and access to your server. These instructions are for Windows based machines but the concepts and tools should work on Mac or Unix based platforms.

1. Install and Setup Tools
Download and Install the Cert Viewer Plus plug-in for Firefox
https://addons.mozilla.org/en-US/firefox/addon/1964

Download and install Portecle JVM certificate manager
(portecle-1.3.zip) You do not need the source (src) version
https://sourceforge.net/projects/portecle
The easiest way to install Portecle is to unzip the contents of the zip file to a directory such as C:\Program Files\portecle-1.3\ Then find the file “Portecle.jar”, right click it and send it to your desktop as a shortcut. You can then use this shortcut to launch Portecle. (optionally you can also change the name of the shortcut and change the icon to use the portecle.ico file for the icon)

2. Extract the Certificate
If you cannot get the certificate you need directly from the issuer, you can get the certificate for the website you are trying to access from the Firefox certificate store using the Cert Viewer Plus plug-in for Firefox.

Under the [Tools] menu in Firefox select [Certificate Manager].
In the Certificate Manager screen, select the certificate desired on either the [Web Sites] or [Authorities] tab. Select the [View] button.
On the Certificate Viewer screen select [Export…]
Select a save location and name for the certificate, save as an X.509 Certificate
Remember the name and location of this certificate.

3. Install Certificate to Java Virtual Machine and/or ColdFusion server
Start Portecele.
On the [File] menu, select [Open Keystore File] navigate to and locate the keystore you are interested in.
For many java installations this will be located in your “jre\lib\security” directory and might be named “cacerts”
For the ColdFusion 8 default developer install the path will be “c:\coldfusion8\runtime\jre\lib\security\cacerts”
You will have to enter the password for the keystore. The default password is “changeit”

Now you are ready to import the key.
From the [Tools] menu select [Import Trusted Certificate]
Navigate to and locate the certificate you saved from Firefox and click [Import]
You will need to reenter the keystore password.
You can change the alias if you desire but I would recommend leaving it as the default
Note: You may also be prompted to “trust” the certificate.

4. Restart you Java Virtual Machine.
For ColdFusion not installed on top of JRun you just need to restart the ColdFusion service. If you are running on top of JRun you also need to restart JRun.

Let me know if this works for you or if you have any further suggestions.

2008.04.21

Can your code be too structured?

I recently had the opportunity to work with some code developed by [NAME WITHHELD TO PROTECT THE INNOCENT] The code is absolutely great code, does some interesting things however…. it was just TOO well organized and way to verbose. Now normally if I’m going to criticize someone’s coding style, (which I generally do not do) it would be for the exact opposite reason as this. However this code was so well structured as to make it difficult to follow, and understand, much less fit on a screen.

Every argument for every CF tag began on it’s own line with every new tag separated by at least one line. Thus causing a single cffunction definition header (without any actual code in) to run to 40+ lines. As here

[VARIABLE AND METHOD NAMES HAVE BEEN MODIFIED IN THE FOLLOWING CODE TO PROTECT THE AUTHORS IDENTITY]

<cffunction
name=”functionName”
access=”public”
returntype=”any”
output=”false”
hint=”provides blah blah blah blah.”>

<!— Define arguments. —>
<cfargument
name=”Name”
type=”string”
required=”true”
hint=”some name.”
/>

<cfargument
name=”Type”
type=”string”
required=”true”
hint=”sometype.”
/>

<cfargument
name=”Location”
type=”string”
required=”false”
default=”here”
hint=”some location”
/>

ETC…..

Additionally inside of a CFswitch statement … every case statement was preceded by the exact same comment and more than sufficiently spaced apart.

<cfswitch expression=”#whatsittype#”>

<cfcase value=”1″>

<!— exact same comment create a type of whatsit—>
<cfset scope.var = {
x = x,
y = y
} />

</cfcase>

<cfcase value=”2″>

<!— exact same comment create a type of whatsit—>
<cfset scope.var = {
x = x,
y = y
z = z
} />

</cfcase>

<cfcase value=”3″>

<!— exact same comment create a type of whatsit—>
<cfset scope.var = {
x = x,
b = b
e = e
z = z
} />

</cfcase>

<cfcase value=”4″>

<!— exact same comment create a type of whatsit—>
<cfset scope.var = {
d = d,
y = y
z = z
} />

</cfcase>

ETC….

Now don’t think that I believe that code needs to be short… I am a big fan of white space where needed… however if I need to scroll the screen to just read the method definition, there is a little too much verbosity in the code.

Coding is very much a matter of personal preference however when publishing code to the public it is generally accepted to follow some general guidelines on form. If you code in this style and share your code with the world… please take the time to condense your code prior to posting.

If you code in this style… why? What are your opinions on this coding style, is it helpful or does it make more work for the next programmer? What kind of style do you program in?

2008.04.15

SQL Script To generate SQL Script

Update! click here to see the sql generation script in a PDF file

Sorry for the odd format but WordPress oddly enough doesn’t allow users to upload simple text files…. Go figure.

—————————-

Well I started out looking for a nice programmatic way to generate my SQL scripts that would generate them in dependency order…. While I found a few things here and there ultimately I ended up taking several of these ideas and creating my own.

I borrowed the part of the code that generates the procs and orders the code from Robbe D. Morris.

I borrowed some of the code to generate the tables from Adam Howitt. I took his ColdFusion Generate SQL Tool and moved it into SQL.

I also found this interesting article on using the program that SQL server itself uses but found it not practical for my purposes where I did not have file level access to the SQL server.

This code will run in MS SQL-2005 server and with some modifications would run in MS SQL-2000 server. The only modifications needed should be to replace the varchar(max) with varchar(7500). Of course doing this will truncate script parts that are longer than 7500… The net result of this could be two fold. Table definitions that are longer than 7500 (not likely) will be truncated. For script based items, view, sp and functions, references that occur after the 7500 char will not be taken into consideration, however the script should still generated correctly.

I make no warranty on this code… it should work. I used it about a month ago but have not had time to go back through and make sure it is all correct. If you see anything that needs correction or would suggest an improvement please post it here.

/**************************************************************************************************
BEGIN TABLE SCRIPT CREATION (this header is repeated at the end)
**************************************************************************************************/
declare @ScriptTable TABLE
(Script varchar(7500), Table_Name varchar(255), ScriptRow int )

—————————————————————————————————-
– ** Add the create table statment and the columns for the tables
—————————————————————————————————-
set nocount ON

insert into @ScriptTable
select Script, Table_Name, ScriptRow from
(
select space(30) +
case when [Column_ID] = 1 then ‘ ‘ else ‘,’ end +
‘['+Column_Name+'] ['+ Column_Type +']‘ +
case
when Column_Type in (‘decimal’,'numeric’) then ‘(‘ +[Column_Precision]+’,'+[Column_Scale]+’)’
when Column_Type in (‘nvarchar’,'nchar’,'varchar’,'char’,'varbinary’,'binary’) then ‘(‘+ [Column_Length] + ‘)’
else ”
end
+ ‘ ‘ + Identity_Script + ‘ ‘ + Column_Nullable

as [Script], [Table_Name], 1000+[Column_ID] as [ScriptRow]
–,*
from(
select
SO.id as [Table_ID],
SO.name as [Table_Name],
AC.[column_id] as [Column_ID],
AC.[Name] as [Column_Name],
type_name(AC.system_type_id) as [Column_Type],
coalesce(SC.text,”) as [Column_Formula],

case
when AC.[max_length] <0 then ‘max’
when type_name(AC.system_type_id) in (‘nchar’,'nvarchar’) then cast(AC.[max_length]/2 as varchar(10))
else cast(AC.[max_length] as varchar(10)) end as [Column_Length],
–convert(int, AC.[max_length]) as [Column_Length],

case when type_name(AC.system_type_id) in (‘tinyint’,’smallint’,'decimal’,'int’,'real’,'money’,'float’,'numeric’,’smallmoney’) then
cast(AC.precision as varchar(20)) else ” end as [Column_Precision],

case when type_name(AC.system_type_id) in (‘tinyint’,’smallint’,'decimal’,'int’,'real’,'money’,'float’,'numeric’,’smallmoney’) then
cast(AC.scale as varchar(20)) else ” end as [Column_Scale],

CASE WHEN AC.[is_nullable] = 1 THEN ‘NULL’ ELSE ‘NOT NULL’ END as [Column_Nullable],
AC.[is_identity] as [Is_Identity],
CASE WHEN AC.[is_replicated] = 0 AND ac.[is_identity] = 1 THEN ‘NOT FOR REPLICATION’ ELSE ” END as [Column_Replication],
AC.[is_ansi_padded] as [Is_ANSI_Padded],
coalesce(IC.[name],”) as [Identity_Name],
CASE WHEN IC.[name] is not null THEN cast(ident_seed(SO.name) as varchar(10)) ELSE ” END as [Identity_Seed],
CASE WHEN IC.[name] is not null THEN cast(ident_incr(SO.name) as varchar(10)) ELSE ” END as [Identity_Increment],

CASE WHEN IC.[name] is not null THEN ‘IDENTITY(‘+ cast(ident_seed(SO.name) as varchar(10)) + ‘,’ + cast(ident_incr(SO.name) as varchar(10)) + ‘)’ ELSE ” END as [Identity_Script]

from [sys].[all_columns] AC
left join [syscomments] SC on AC.[object_id] = SC.[id] and AC.[column_id] = SC.[number]
left join [sysobjects] SO on AC.[object_id] = SO.id
left join [sys].[identity_columns] IC on AC.[object_id] = IC.[object_id] and AC.[column_id] = IC.[column_id]
where SO.xtype = ‘U’
) info

union — Add in the opening part
select ‘CREATE TABLE [DBO].[' + SO.[Name] + ‘] (‘ as [Script], SO.[Name] as [Table_Name], 1000 as [ScriptRow] from [sysobjects] SO where xtype = ‘U’

union — Add in the closeing part
select ‘) ‘ as [Script], SO.[Name] as [Table_Name], 2001 as [ScriptRow] from [sysobjects] SO where xtype = ‘U’

union — Add in the closeing part
select ‘ ‘ as [Script], SO.[Name] as [Table_Name], 2002 as [ScriptRow] from [sysobjects] SO where xtype = ‘U’

) combined
–where Table_Name like ‘air%’
order by Table_Name, ScriptRow

—————————————————————————————————-
– ** Update for formulas for computed columns
—————————————————————————————————-

update ST
set Script = F.Script
from
@ScriptTable ST inner join
–select Script, TableName, ScriptRow from
(select space(30) +
case when [Column_ID] = 1 then ‘ ‘ else ‘,’ end +
‘[' + ac.name +'] AS ‘ + sc.text as Script,
so.name as Table_Name,
sc.number + 1000 as ScriptRow
from
sysobjects so left join syscomments sc on so.id = sc.id
left join sys.all_columns ac on sc.id = ac.[object_id] and sc.number = ac.[column_id]
where
so.xtype = ‘U’ — Is user defined table
and
sc.number is not null — number is the column number
) F
on ST.Table_Name = F.Table_Name and ST.ScriptRow = F.ScriptRow

—————————————————————————————————-
– ** Add the index create statements (3000)
—————————————————————————————————-
declare @ScriptText varchar(7500)
declare @TableNameText varchar(255)
declare @ScriptRowInt int

declare @i int
declare @keyCols varchar(2000)

declare @ScriptCursor CURSOR

set nocount ON

insert into @ScriptTable
select
‘CREATE ‘ + UniqueText + ClusterText + ‘ INDEX [' + [Index_Name] + ‘] ON [DBO].['+[Table_Name]+’]’ — (‘ + TargetField
as [Script],
Table_Name as [Table_Name],
3000 + (indexID*2) as [ScriptRow]
from(
select
i.index_id as IndexID,
i.name as Index_Name,
case when i.type_desc = ‘CLUSTERED’ then ‘CLUSTERED’ else ‘NONCLUSTERED’ end as ClusterText,
case when i.is_unique = 1 then ‘UNIQUE ‘ else ” end as UniqueText,
s.[object_id] as Table_ID,
so.name as Table_Name
from [sys].[indexes] I
left join [sys].[stats] S on I.[object_id] = S.[object_id] and I.[index_id] = S.[stats_id]
left join [sysobjects] SO on S.[object_id] = SO.[id]
–left join [sys].[all_columns] AC on S.[object_id] = AC.[object_id]
where so.xtype = ‘U’
) inside
WHERE Table_Name in (Select distinct Table_Name from @ScriptTable)
order by [Table_Name], [ScriptRow]

SET @ScriptCursor = CURSOR
FOR
select [Script], [Table_Name], [ScriptRow]
from @ScriptTable
where ScriptRow > 3000 and ScriptRow < 4000
FOR UPDATE

set nocount ON

OPEN @ScriptCursor
FETCH NEXT FROM @ScriptCursor INTO @ScriptText,@TableNameText, @ScriptRowInt
WHILE @@FETCH_STATUS = 0
BEGIN
set @keyCols = ”
set @i = 1
WHILE index_col( @TableNameText, (@ScriptRowInt – 3000)/2, @i) IS NOT NULL
BEGIN
if @i > 1 begin set @keyCols = @keyCols + ‘,’ end
set @keyCols = @keyCols + index_col( @TableNameText, (@ScriptRowInt – 3000)/2, @i)
set @i = @i + 1
END
UPDATE @ScriptTable SET [Script] = @ScriptText + ‘ (‘ + @keyCols + ‘)’ WHERE CURRENT OF @ScriptCursor
–PRINT ‘–’ + @ScriptText + ‘:’ + @TableNameText + ‘:’ + @keyCols — + @ScriptRowInt
FETCH NEXT FROM @ScriptCursor INTO @ScriptText,@TableNameText, @ScriptRowInt
END
DEALLOCATE @ScriptCursor

– ** Insert the ‘GO’ Statements afer each index create
insert into @ScriptTable
select ‘ ‘ as Script, Table_Name, ScriptRow + 1 as ScriptRow from @ScriptTable where ScriptRow > 3000 and ScriptRow < 4000 and Script like ‘CREATE%’

—————————————————————————————————-
– ** Add the DEFAULT contraints (4000)
—————————————————————————————————-
insert into @ScriptTable
select
‘ ADD CONSTRAINT ['+DC.[Name]+’] DEFAULT ‘+DC.[definition]+ ‘ FOR ['+ col_name(SO.[parent_obj], [parent_column_id]) +’]’ as Script,
PSO.[Name] as Table_Name,
([parent_column_id]*3) + 4000 as ScriptRow
from sys.default_constraints DC
left join sysobjects SO on DC.object_id = SO.id
left join sysobjects PSO on SO.[parent_obj] = PSO.id
where
PSO.[Name] in (Select distinct Table_Name from @ScriptTable)

– ** Insert the ‘GO’ Statements afer each constraint create
insert into @ScriptTable
select ‘ ‘ as Script, Table_Name, ScriptRow + 1 as ScriptRow from @ScriptTable where ScriptRow > 4000 and ScriptRow < 5000 and Script like ‘ ADD CONSTRAINT%’

– ** Insert the ‘ALTER TABLE’ part of the statement before each constraint
insert into @ScriptTable
select ‘ALTER TABLE [DBO].['+Table_Name+']‘ as Script, Table_Name, ScriptRow – 1 as ScriptRow from @ScriptTable where ScriptRow > 4000 and ScriptRow < 5000 and Script like ‘ ADD CONSTRAINT%’

—————————————————————————————————-
– ** Add the FOREIGN CONSTRAINTS
—————————————————————————————————-
declare @fkcursor cursor
declare @fkeyid int, @rkeyid int, @cnstid int, @fkeycol smallint, @rkeycol smallint, @fkeycounter int
declare @parentTbl varchar(300), @referenceTble varchar(300), @keyName varchar(300), @keys varchar(500), @cnstdes varchar(500)

set @fkeycounter = 5001

set @fkcursor = cursor for
select
FK.[object_id], FK.parent_object_id, FK.referenced_object_id,
SO.name as KeyName, PSO.name as ParentTable, RSO.name as ReferenceTable
from
sys.[foreign_keys] FK
left join sysobjects SO on FK.object_id = SO.id
left join sysobjects PSO on FK.[parent_object_id] = PSO.id
left join sysobjects RSO on FK.[referenced_object_id] = RSO.id
WHERE PSO.name in (Select distinct Table_Name from @ScriptTable)

open @fkcursor
fetch @fkcursor into @cnstid, @fkeyid, @rkeyid, @keyName, @parentTbl, @referenceTble
WHILE @@FETCH_STATUS = 0
Begin
declare ms_crs_fkey cursor local for
select parent_column_id, referenced_column_id from sys.foreign_key_columns where constraint_object_id = @cnstid
open ms_crs_fkey
fetch ms_crs_fkey into @fkeycol, @rkeycol
select @keys = col_name(@fkeyid, @fkeycol), @cnstdes = col_name(@rkeyid, @rkeycol)
fetch ms_crs_fkey into @fkeycol, @rkeycol
while @@fetch_status >= 0
begin
select @keys = @keys + ‘, ‘ + col_name(@fkeyid, @fkeycol),
@cnstdes = @cnstdes + ‘, ‘ + col_name(@rkeyid, @rkeycol)
fetch ms_crs_fkey into @fkeycol, @rkeycol
end

insert into @ScriptTable(Script,Table_Name,ScriptRow)
values(‘ALTER TABLE DBO.['+@parentTbl+'] ADD CONSTRAINT ['+@keyName+']‘,@parentTbl ,@fkeycounter)

insert into @ScriptTable(Script,Table_Name,ScriptRow)
values(‘ FOREIGN KEY (‘+ @keys + ‘) REFERENCES DBO.[' + @referenceTble+ '] (‘ + @cnstdes +’)',@parentTbl,@fkeycounter+1)

insert into @ScriptTable(Script,Table_Name,ScriptRow)
values(‘ ‘,@parentTbl,@fkeycounter+2)

deallocate ms_crs_fkey
set @fkeycounter = @fkeycounter + 6
fetch next from @fkcursor into @cnstid, @fkeyid, @rkeyid, @keyName, @parentTbl, @referenceTble
end

– ** Insert the ‘A comment before each table create and space after’
insert into @ScriptTable
select distinct
‘/* [' + Table_Name +'] */’ as Script,
Table_Name, 900 as ScriptRow from @ScriptTable

insert into @ScriptTable
select distinct
‘ ‘ as Script,
Table_Name, 9000 as ScriptRow from @ScriptTable

– Clean the Results
delete from @scripttable where table_name like ’sys%’ or table_name = ‘dtproperties’

– Parse the code into the final table
declare @tablesScript TABLE (table_name varchar(255), script varchar(7500))

declare @finalCursor CURSOR

declare @builduptext varchar(7500)
set @builduptext = ”

set @finalCursor = cursor for
select Script, Table_Name, ScriptRow from @scripttable order by table_name, scriptrow

OPEN @finalCursor
FETCH NEXT FROM @finalCursor INTO @ScriptText,@TableNameText, @ScriptRowInt
WHILE @@FETCH_STATUS = 0
Begin
if(@ScriptRowInt = 9000)
begin
insert into @tablesScript(table_name, script) values (@TableNameText, @BuildUpText + char(13) + @ScriptText )
set @builduptext = ”
end
else
begin
set @builduptext = @builduptext + char(13) + @ScriptText
end
FETCH NEXT FROM @finalCursor INTO @ScriptText,@TableNameText, @ScriptRowInt
END
deallocate @finalcursor

– Contents of table script are now located in the @tablesScript temporary table
/**************************************************************************************************
END TABLE SCRIPT CREATION (this footer is repeated at the begining)
**************************************************************************************************/

/**************************************************************************************************
BEGIN PROGRAMABILITY SCRIPT CREATION (this footer is repeated at the end)
**************************************************************************************************/

declare @procsCursor CURSOR

set @procsCursor = CURSOR FOR
select distinct
upper(SysObjects.Name) as ObjectName
from SysObjects
where (SysObjects.Category = 0) and
SysObjects.type in (‘P’,'FN’,'TF’,'V’) and –Only want procs, functions and views
not (upper(left([SysObjects].[Name],3)) in (‘SP_’,'DT_’,'XP_’,'ZZZ’,'FN_’))

declare @objectName varchar(255)
declare @OutStringP varchar(MAX)
declare @InStringP varchar(255)
declare @TempCursorP CURSOR

declare @TempTableP TABLE
( [text] varchar(7500) )


declare @programScript TABLE ([object_name] varchar(255), script varchar(max) ) — varchar(8000))

declare @scriptString varchar(max)
set @scriptString = ”

declare @tlen float

INSERT into @programScript([object_name],script) values(@objectName, ”)

OPEN @procsCursor FETCH NEXT FROM @procsCursor into @objectName
WHILE @@FETCH_STATUS = 0
BEGIN
set @tlen = 0

set @OutStringP = ”
set nocount ON
insert into @TempTableP exec sp_helptext @objectName
SET @TempCursorP = CURSOR FAST_FORWARD FOR select [Text] from @TempTableP

OPEN @TempCursorP FETCH NEXT FROM @TempCursorP INTO @InStringP
WHILE @@FETCH_STATUS = 0
BEGIN
IF(len(@InStringP) < 255)
BEGIN
IF(LEN(LTRIM(RTRIM(@OutStringP + @InStringP))) > 0)
BEGIN
set @scriptString = @scriptString + CAST(@OutStringP AS varchar(max)) + CAST(@InStringP AS varchar(max))
set @tlen = @tlen + len(@outStringP + @InStringP)
–UPDATE @programScript set [script] = [script] + @OutString + @Instring where [object_name] = @objectName

–print RTRIM(@OutString + @InString)
END
set @OutStringP = ”
END
ELSE
BEGIN
set @OutStringP = @OutStringP + @InStringP
END

FETCH NEXT FROM @TempCursorP INTO @InStringP
END

INSERT into @programScript([object_name],script) values(@objectName, @scriptString)

set @scriptString = ”

CLOSE @TempCursorP
DEALLOCATE @TempCursorP
DELETE FROM @TempTableP
FETCH NEXT FROM @procsCursor INTO @objectName
END

– Contents of procs/views/functions script are now located in the @programScript temporary table
/**************************************************************************************************
END PROGRAMABILITY SCRIPT CREATION (this footer is repeated at the begining)
**************************************************************************************************/

set nocount on

declare @ProcName nvarchar(100)
declare @ProcSortOrder varchar(30)
declare @MyCursor CURSOR
declare @ObjectType char(2)
declare @TypeString varchar(20)
declare @CheckParm varchar(20)

declare @ProcedureCode varchar(7500)

declare @TempCursor CURSOR
declare @InString varchar(7500)
declare @OutString varchar(7500)
declare @TempTable TABLE
( [text] varchar(7500) )

declare @StoredProcs TABLE
(
SortOrder int,
ProcedureName varchar(255),
ProcedureCode varchar(max),
ObjectType char(2),
TypeString varchar(20),
CheckParm varchar(20),
UsedBy int,
Uses int

)

set nocount ON
Insert Into @StoredProcs
select distinct
case SysObjects.type
when ‘FN’ then 1 –IsScalarFunction
when ‘TF’ then 2 –IsTableFunction
when ‘V ‘ then 5 –IsView
when ‘U’ then 4 –IsTable
ELSE 3 –IsProcedure
end as SortOrder,

upper(SysObjects.Name),
case SysObjects.type
when ‘U’ then TS.script
else PS.script — SysComments.Text
END as ProcedureCode,
SysObjects.type,
case SysObjects.type
when ‘P ‘ then ‘Procedure’
when ‘V ‘ then ‘View’
when ‘U’ then ‘Table’
ELSE ‘Function’
END as TypeString,
case SysObjects.type
when ‘FN’ then ‘IsScalarFunction’
when ‘TF’ then ‘IsTableFunction’
when ‘V ‘ then ‘IsView’
when ‘U’ then ‘IsTable’
ELSE ‘IsProcedure’
END as CheckParm,
0 as UsedBy,
0 as Uses

from SysObjects –left join SysComments on SysObjects.ID = SysComments.ID
left join @tablesScript TS on SysObjects.Name = TS.table_name
left join @programScript PS on SysObjects.Name = PS.[object_name]
where
SysObjects.type in (‘P’,'FN’,'TF’,'V’,'U’) and –Only want procs, functions and views
(SysObjects.Category = 0)
and not (upper(left([SysObjects].[Name],3)) in (‘SP_’,'DT_’,'XP_’,'ZZZ’,'FN_’)) –exclude system and ZZZ hidden stuff
–order by SysObjects.Name ASC

–select count(sortorder), procedureName from @StoredProcs group by procedureName order by ProcedureName

–create table ##SPuses
declare @SPuses TABLE
(
[ObjectName] varchar(255),
UsesName varchar(255),
Lvl int,
Ord int
)

declare @level int
set @level = 1

declare @rowsAffected int
set @rowsAffected = 1000

–insert into @spuses
insert into @SPuses
select
A2.ProcedureName as [ObjectName],
B2.ProcedureName as [UsesName],
1 as Lvl,
0 as Ord
from @StoredProcs A2 left join @StoredProcs B2
on (REPLACE(UPPER(A2.ProcedureCode),A2.ProcedureName,”)
LIKE ‘%’ + upper(B2.ProcedureName) + ‘%’)
order by A2.SortOrder DESC

update SP set
UsedBy = coalesce(SPAg.UsedByCount,0),
Uses = coalesce(SPAg2.UsesCount,0)
from @StoredProcs SP
left join
(select count(ObjectName) as UsedByCount, UsesName from @SPuses –@spuses
group by UsesName) SPAg
on SP.ProcedureName = SPAg.usesName
left join
(select count(UsesName) as UsesCount, ObjectName from @SPuses –@spuses
where UsesName is not null group by ObjectName) SPAg2
on SP.ProcedureName = SPAg2.ObjectName

while @rowsAffected > 0
begin
insert into @SPuses
select distinct
SP1.ObjectName as [ObjectName],
SP2.UsesName as [UsesName],
@level + 1 as Lvl,
0 as Ord
from
@SPuses SP1 left join @SPuses SP2 on SP1.UsesName = SP2.ObjectName
where SP1.UsesName is not null and SP2.UsesName is not null
and
SP1.lvl = @level

set @rowsAffected = @@rowcount
–print @rowsAffected

set @level = @level + 1
end

insert into @SPuses
select distinct ObjectName, UsesName, 0 as Lvl, 1 as Ord
from @SPuses order by ObjectName

delete from @SPuses where Ord = 0

update @SPuses set Ord = 0

set @level = 1
update @SPuses set Ord = @level where usesName is null
set @rowsAffected = @@rowcount
–print @rowsAffected

while @rowsAffected > 0
begin
update @SPuses set Ord = @level + 1 where usesName in (select ObjectName from @SPuses where Ord = @level)

set @rowsAffected = @@rowcount
– print @rowsAffected

set @level = @level + 1
end

set nocount ON

SET @MyCursor = CURSOR SCROLL –FAST_FORWARD
FOR
select ProcedureName,
cast(outC.SortOrder as varchar(2)) +’.'+ cast(outC.MxOrd as varchar(2)) +’.'+ cast(outC.AvOrd as varchar(2)) +’.'+ cast(outC.MnOrd as varchar(2)) as SortOrder
,ObjectType
,TypeString
,CheckParm
,ProcedureCode
from
(
select distinct ProcedureName,
SortOrder

,ObjectType
,TypeString
,CheckParm
,ProcedureCode
,B.MxOrd, B.AvOrd, B.MnOrd
from @StoredProcs A

left join (select max(ord) as MxOrd, Avg(ord) as AvOrd, min(ord) as MnOrd, ObjectName from @SPuses group by ObjectName ) B

on A.ProcedureName = B.ObjectName
) outC
order by outC.SortOrder, outC.MxOrd, outC.AvOrd, outC.MnOrd

–select max(ord) as MxOrd, Avg(ord) as AvOrd, min(ord) as MnOrd, ObjectName from @SPuses group by ObjectName order by MxOrd, AvOrd, MnOrd

—————————-
set nocount ON

print’——————————————————————————————’
Print ‘– The procs/functions and views will be generated in the following order [Rank]‘
print ‘ ‘
OPEN @MyCursor
FETCH NEXT FROM @MyCursor INTO @ProcName,@ProcSortOrder, @ObjectType, @TypeString, @CheckParm, @ProcedureCode
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT ‘–’ + @ObjectType + ‘ : ‘+ left(@TypeString+’ ‘,10) + ‘: ‘+ @ProcName + ‘ ['+ cast(@ProcSortOrder as varchar(20)) +']‘
FETCH NEXT FROM @MyCursor INTO @ProcName,@ProcSortOrder, @ObjectType, @TypeString, @CheckParm, @ProcedureCode
END
set nocount ON

FETCH FIRST FROM @MyCursor
INTO @ProcName,@ProcSortOrder,@ObjectType,@TypeString,@CheckParm, @ProcedureCode
WHILE @@FETCH_STATUS = 0
BEGIN
print ‘–===============================================================================’
–PRINT ‘if exists (select * from dbo.sysobjects ‘
–PRINT ‘ where id = object_id(N’ + char(39) + ‘[dbo].[' + @ProcName + ']‘ + char(39) + ‘)’
–PRINT ‘ and OBJECTPROPERTY(id, N’ + char(39) + @CheckParm + char(39) + ‘) = 1) ‘
– PRINT ‘ drop ‘ + @TypeString+’ ‘ + @ProcName
– PRINT ‘ GO ‘
– PRINT ‘ SET QUOTED_IDENTIFIER OFF ‘
– PRINT ‘ GO ‘
– PRINT ‘ SET ANSI_NULLS OFF ‘
– PRINT ‘ GO’

/*if @TypeString = ‘Function’ or @TypeString = ‘Procedure’ or @TypeString = ‘View’
begin

end*/

if @TypeString = ‘Table’
begin
print @ProcedureCode
end
else
begin
print ‘GO’
– exec sp_helptext @ProcName
– The following section compensates for the way sp_helptext handles wrapping
———————————————
set @OutString = ”
set nocount ON
insert into @TempTable exec sp_helptext @ProcName
SET @TempCursor = CURSOR FAST_FORWARD FOR select [Text] from @TempTable

OPEN @TempCursor FETCH NEXT FROM @TempCursor INTO @InString
WHILE @@FETCH_STATUS = 0
BEGIN
IF(len(@InString) < 255)
BEGIN
IF(LEN(LTRIM(RTRIM(@OutString + @InString))) > 0)
BEGIN
print RTRIM(@OutString + @InString)
END
set @OutString = ”
END
ELSE
BEGIN
set @OutString = @OutString + @InString
END

FETCH NEXT FROM @TempCursor INTO @InString
END

CLOSE @TempCursor
DEALLOCATE @TempCursor
DELETE FROM @TempTable

–if @TypeString = ‘Function’ or @TypeString = ‘Procedure’ or @TypeString = ‘View’
–begin
print ‘GO’
–end

—————————————————–
end
– PRINT ‘ GO ‘
– PRINT ‘ SET QUOTED_IDENTIFIER OFF ‘
– PRINT ‘ GO ‘
– PRINT ‘ SET ANSI_NULLS ON ‘
– PRINT ‘ GO ‘
– PRINT ”
– PRINT ‘ GRANT EXECUTE ON [dbo].[' + @ProcName + '] TO [' + @ProcUser + ']‘
– PRINT ‘ GO ‘

FETCH NEXT FROM @MyCursor

INTO @ProcName,@ProcSortOrder,@ObjectType,@TypeString,@CheckParm, @ProcedureCode
END

CLOSE @MyCursor
DEALLOCATE @MyCursor

2008.03.25

banner puzzle game is OVER

Well it had to come to an end…. after a little over a year I figured it was time to finally swap out my banner and end my little hidden puzzle challenge. Since moving to wordpress, I no longer have ColdFusion server space. Therefore the way to get to the puzzle solution is no longer available. Over the course of the last year or so I had just 16 people (that I know of) guess that there was a hidden message in the banner. Of those 16 only 5 people figured out what the message was and how to get to the secret page on the site. I wish that I was able to leave the solution page up but it just was not possible without the ColdFusion server. For those people who solved the puzzle and found the solution page…. “Toe (see). Do (see)….” For everyone else I’ll leave the banner here if you think you can figure it out let me know what your solution would be. If you are correct I’ll send you a static copy of the solution page. As a hint… this is a two parter, both the map and the key are embedded in the banner. flexusbanner

2008.03.24

Blog Moved

I finally did it… I got tired of paying for my crippled ColdFusion hosting account so I’ve moved my blog over to wordpress. I have also taken the extra step of splitting up my personal blog from my programming blog. I have gotten increasing amounts of traffic for both areas and felt it was just time to separate the two out. Officially the URLS are now:

For my programming blog: http://blog.flexuous.com/

For my personal blog: http://blog.justinohms.com/

In one of my future posts I plan to include my methodology for moving my blog over including redirects for search engines so that I don’t loose my page rankings and any other links that are out there.

2007.10.18

Yippie !! New Phone….

So I’ve had my Treo 600 for 4 or 5 years now ever since they first came out. When I first got my Treo I absolutely loved it but as time went on well… there were newer and cooler phones out. Steph got a new Blackberry through work about a year ago so stopped using her Treo and then earlier this month one of the chargers for the Treo broke…. I took that as a sign and decided to stop putting of the inevitable and just go buy a new phone.

I’ve had my eye on a number of phones/pdas over the last 2 years…. the Cingular 8525, the Treo 700p, the iPhone while they each had their pluses and minuses I decided eventually to settle on the Nokia N95. This had all the features I wanted and is only lacking in one small way.

Here is a quick summary of the features…

“GSM, EDGE and 3G support

WIFI 802.11b/g support

Bluetooth (GPS, keyboard, or as a modem)

MicroSD (comes with a 1G card but I bought an extra 2G)

GPS with voice navigation (via internal GPS antenna or external bluetooth device)

infrared

5 Mega Pixel camera with flash and lens cover

Video recorder capable

2nd camera on the front

supports video conferenceing

MP3 music player

MP4 video player

FM radio

Internet Tellephone (VOIP)

Internet browser based on the web kit engine

Flash Lite

Java J2ME applications

email (POP & IMAP)

contacts/IM/Video IM/calendar/notes/to do/ (and it syncs to Outlook)

PDF reader

MS Office document support (Word, Excel, Power Point)

Zip File support

bar code reader (using the camera)

Voice recorder

Oh yeah I almost forgot the best part… It’s also a cell phone.

Here is a photo of my new phone next to my old Treo

Treo 600 and Nokia N95

The front cover/screen can slide up/left to work in portrait mode and reveal the phone keypad, or down/right to work in landscape mode and reveal the media player controls. Now to top it all off the N95 is quite a bit smaller than my Treo (and it doesn’t have the antenna sticking up)

I haven’t had a chance to really play with all of the features yet but I am looking forward to testing them all out on our trip to St. Louis next week. Oh and that one thing that is lacking… the N95 does not have a full alpha keyboard like the Treo or a BlackBerry so you have to use the standard telephone keypad to enter alpha characters.

2007.10.09

ColdFusion 8 flex2gateway Error 500 java.lang.NullPointerException

I recently upgraded to CF8 and experienced a small problem when i went to configure my AMF end points and channels. First I must say that I like the new method of keeping the channel definitions in the services-config while breaking out the destination settings into separate files like remoting-config. Now all that being said I encountered the following error when going to http://localhost/flex2gateway/
after copying over my old settings into these files.

500

java.lang.NullPointerException
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:283)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)
at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203)
at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)

The problem occurs because apparently while it was ok to have two channels share the same endpoint uri URL in CF7…

2007.10.03

SquidHead 2.0 – ColdFusion + SQL CRUD generator

Terrence Ryan has done it again and updated his Squidhead tool with a better interface and design. The new version includes support for mySQL (not a big deal to me but important to a lot of people.) If you come from a database background or just like to begin your project at the data design level you should check it out.

You can check out Terrence’s blog here and download Squidhead 2.0 from reaforge.

2007.07.27

SQL Server : TDSSNIClient initialization failed with error 0×5, status code 0×51.

Ok.. I was getting the following error in my event viewer/application log when I would try to start SQL server. I would try to start it and it would immediately fail.

“TDSSNIClient initialization failed with error 0×5, status code 0×51.”

The solution turned out to be rather simple; Open up SQL Configuration manager, and switch the account that the SQL server was running under to the Local System account.

Not necessarily secure, and wouldn’t do it for production but since I do development, it doesn’t matter too much. I’m not sure what caused this problem I recently went through the hell of installing Adobe CS3 but I’ve also had a number of packages get pushed down from the corporate SMS system as well.

Oh, I was also getting the following error in the application log.
UpdateUptimeRegKey: Operating system error 5(Access is denied.) encountered.
The trick for this one is just to go change the permissions in the registry so the MicrosoftSQL keys can be updated.

2007.07.24

RDS configuration in FlexBuilder 3 cannot connect

After my install of FlexBuilder3 (after my install of CS3) I was having a problem connecting to my local RDS server. What made this particular problem really odd is that I was not having this problem in FlexBuilder2. (With FB2 I could connect to my RDS server just fine) The other thing that made this odd, was that I knew for a fact that I was able to use FB3 to connect to my local RDS server.

The only difference in configuration between FB2 and FB3 that I could remember making was that in FB3 I used the “”Software Updates”" feature when I was at work so I had to enable the HTTP proxy connection for Install/Updates. I tried to disable this feature (Preferences – Install/Update – Proxy Settings) but still no luck. … after messing around with it for a little longer I figured out that this was the correct solution but FlexBuilder needed to be restarted. Apparently the RDS Configuration in FlexBuilder uses the same proxy settings as the Install/Updates HOWEVER in order for that change to take effect, you have to close and reopen FlexBuilder.