Archive for the ‘Code’ Category
CREATE FUNCTION [dbo].[DateOnly] (@Date DATETIME)
RETURNS DATETIME
BEGIN
RETURN DATEADD(d, DATEDIFF(d, 0, @Date), 0)
END
Posted in Code, Database, MSSQL2005, MSSQL2008, Quick Tips, SQL Server, Software Development, TSQL | No Comments »
CREATE FUNCTION [dbo].[LastDayOfTheMonth] (@Date DATETIME )
RETURNS DATETIME
BEGIN
RETURN dateadd(ms, -3, DATEADD(mm, DATEDIFF(m, 0, @Date) + 1, 0))
END
Posted in Code, MSSQL2005, MSSQL2008, Quick Tips, SQL Server, TSQL | No Comments »
When I installed Zend Server CE on OSX 10.6 Snow Leopard the admin interface failed, the following fixed the issue :
1. Download this: Watchdog update
2. Backup watchdog with the command
sudo mv /usr/local/zend/bin/watchdog /usr/local/zend/bin/watchdogOLD
3. Extract the new watchdog to /usr/local/zend/bin/ (I used the go to folder in finder, if you can view hidden files)
4. Run the following command to restart the Zend server
sudo /usr/local/zend/bin/zendctl.sh restart
Posted in MySQL, PHP | No Comments »
1: Delete It !
If a chunk of code comment or class is not used, don’t comment it out, just delete it.
2: Write clear code.
“make sure you document code that’s hard to understand”. Question: why is the code hard to understand?
3: Comment
Comments can indeed be useful but mostly as a summary of action
4: Don’t Repeat Yourself
Duplication is bad. If you have more than 4-5 lines of code that do the same thing in a single class, refactor to remove duplication.
Posted in .NET, C#, Code, Java, Objective-C, PHP, Quick Tips, Software Development | No Comments »
If you want to check if a Javascript function exists before you attempt to call it and get an error try:
if(typeof window.Function == 'function') {
// function exists
Function();
}
Posted in Code, Javascript, Quick Tips | 1 Comment »
Apple has announced the iPhone 3.0 software update which includes an updated Software Development Kit (SDK) with over 1,000 completely new APIs.
Here are a few highlighted features:
- Search your iPhone
- Cut, copy, and paste
- Send photos, contacts, audio files, and location via MMS*
- Read and compose email and text messages in landscape
And yes, I am running it (I have an Apple Developer Account), and so far I found one bug (on safari re-highlighting the address bar can sometimes make the address disapear) and an un-announced fearure (the call history list is now much more verbose)
Posted in Code, Objective-C, Platform, Software Development, iPhone | No Comments »
If you need to access SVN remotely, by default it runs on port TCP port 3690, so you need to make sure it is open in your firewall etc.
Posted in .NET, C#, Code, OSX, Platform, Quick Tips, Software Development, Unix/Linux, Windows | 1 Comment »
If you like to know what’s changing on your SQL Server then the following code creates an audit table and the associated trigger for logging the changes
The Audit Object Table
CREATE TABLE [dbo].[AuditObjects](
[EventID] [int] IDENTITY(1,1) NOT NULL
,[EventData] [xml] NULL
PRIMARY KEY CLUSTERED (
[EventID] ASC
) WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
And the associated Trigger
CREATE TRIGGER [TriggerAuditObjects]
ON DATABASE
FOR DDL_DATABASE_LEVEL_EVENTS
AS
INSERT INTO [dbo].[AuditObjects](EventData)
SELECT EVENTDATA()
GO
ENABLE TRIGGER [TriggerAuditObjects] ON DATABASE
You can now use xpath queries to analyse the data
Posted in Code, MSSQL2005, MSSQL2008, Objective-C, SQL Server, Software Development, TSQL, iPhone | 1 Comment »
Ever had the need to search stored procedures to find redundant tables or text that needs replacing or re-factoring ?
Here’s a script to help (Sorry for the cursor, I’m sad with myself for using it
)
-- Search string
DECLARE @SearchString nvarchar(50)
SET @SearchString = 'Search String'
-- Required Declares
DECLARE @getdbname sysname
DECLARE @sqlstm nvarchar(1000)
DECLARE SeachCursor cursor FOR
-- Get All The Names into the SeachCursor
SELECT '['+name+']' FROM [master].[dbo].[sysdatabases] ORDER BY name
OPEN SeachCursor
-- Add the Search Pattern
SET @SearchString = '%' + @SearchString + '%'
--Get the first Name
FETCH NEXT FROM SeachCursor INTO @getdbname
WHILE @@FETCH_STATUS=0
BEGIN
--set the statement to define the search condition, with variables
SET @sqlstm = '
SELECT [SP].[Specific_Catalog] AS [Database_Name], [SP].[Routine_Name] AS [Stored Procedure Name],[SP].[Routine_Definition] AS [Routine_Definition]
FROM '+ @getdbname+'.[Information_Schema].[Routines] AS [SP]
WHERE PatIndex('+''''+@SearchString+''''+', [Routine_Definition]) > 0'
--Execute the Query
EXEC (@sqlstm)
FETCH NEXT FROM SeachCursor INTO @getdbname
END
--Close the Cursor and Deallocate it from memory
CLOSE SeachCursor
DEALLOCATE SeachCursor
Posted in Code, Database, MSSQL2005, MSSQL2008, Objective-C, Quick Tips, SQL Server, TSQL, iPhone | No Comments »
If you get the error in the SQL 2008 Management Studio :
“Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can’t be re-created or enabled the option Prevent saving changes that require the table to be re-created.”
You can enable changes inside the Microsoft SQL Server Management Studio by going to ‘Tools|Options|Designers’ then unchecking the ‘Prevent saving changes that require table re-creation’ option
Posted in Database, MSSQL2008, SQL Server, TSQL | 12 Comments »