Posts

Mobile Development on iphones, weird font sizes and -webkit-text-size-adjust

There are issues with CSS displays for iphones and mobile devices where the browsers are increasing the size of seemingly random pieces of content. This occurs when the browser tries to shrink the content into the screen size. This is resolved by starting development in a greenfield site with the normalize.css which resets the defaults to so that you can start from scratch and build consistent CSS! The main issue turns out to be the CSS attribute  -webkit-text-size-adjust  which will be reset to 100% (there are similar attributes  -ms-text-size-adjust for the other browser types). Of course best practice would be to not use any px measurements also so that the screen can shrink and expand naturally.

SQL Common Table Expression (CTE) Date Ranges with recursive Transact SQL Queries

Now often I've got to product different date ranges of reports (ok always), such as quarterly, monthly, weekly (starting on a Monday!) and by Financial Year. With application programmers liking to build massive amounts of code to loop through dates and repeatedly query the database where as I like to be able to see the data before I design any reports, I was always copy pasting a CTE query template I had for day by day, month by month etc reports. After losing my template, I decided to write the template as a function return a table data type, which then lets me just select the function in my query like so; select vdr.theRangeStart, vdr.theRangeEnd from viewDateRange('MONTH', '20121105', '20130605') vdr Note that the results of this look odd at the start and the end; which is by design; theRangeStart        theRangeEnd 2012-11-05 00:00:00.000    2012-12-01 00:00:00.000 2012-12-01 00:00:00.000    2013-01-01 00:00:00.000 2013-01-...

Find and kill a SQL query

The ColdFusion calls to external systems will just hang around FOREVER waiting for a reply, until the server just gives up! This is because like any good application software, it can't really be sure that it "should" be able to terminate any connection it is waiting for in case it is waiting for something really important (maybe a booking receipt, or credit card payment receipt!!). Clearly some will be outside your control, but when a dodgy SQL query has gone ape, you can always kill that on the database and release the ColdFusion thread and everything will return to normal. Find the session in SQL like so:  select sq.text,r.session_id,r.status,r.command,r.cpu_time,r.total_elapsed_time from sys.dm_exec_requests r cross apply sys.dm_exec_sql_text(sql_handle) AS sq Then issue the KILL command. KILL 59 -- where 59 is the value from session_id.

Railo vs ColdFusion cfqueryparam and SQL HashBtytes

While testing an application against Adobe ColdFusion vs Railo 4.2.1 ; everything went quite well except for a simple piece of inline SQL for an a legacy appication with a bit HashBytes encryption. Nothing too fancy there, just comparing Hashed String with an inputted string, like so:  .... where hashedkey =HashBytes('SHA1', <cfqueryparam cfsqltype="cf_sql_varchar" value="#variables.unhashedkey#">) Except... The input of HashBytes is a binary. Adobe CF, created the hashedkey (elsewhere) with a cfqueryparam type of  cf_sql_varchar but not cast/ converted as a binary. There was no cf_sql_nvarchar which was added in CF10,   Railo came back with a different results here running this code on each environment: <cfquery name="qryInteresting" datasource="datasource"> select hashbytes('SHA1', 'poodle') nocfqueryparam , hashbytes('SHA1', cast('poodle' as varchar(50) ) ) nocfqueryparamC...

Searching for text in a database with ApexSQL

While http://www.red-gate.com/ provides some good search functionality (for FREE) for looking through the objects for reference code, I used to use the " FindMyData_String " procedure below (I would give a reference and amend the post if I could find where it came from). This was a blunt tool, which I never really changed or modified and only pointed me in the right direction to where the data might be. Now I use http://www.apexsql.com/sql_tools_search.aspx ; this is FREE and awesome; you can select the database, tables, type of columns, dateformate etc etc, and it is very fast. just download it and check it out on your dev machine. It will tell you the column and the value so you can see exactly what you are looking for. Blunt Tool for searching all tables ALTER PROCEDURE [dbo].[FindMyData_String] @DataToFind NVARCHAR(4000), @ExactMatch BIT = 0 AS SET NOCOUNT ON DECLARE @Temp TABLE(RowId INT IDENTITY(1,1), SchemaName sysname, TableName sysname, ColumnName SysNa...

Organizing SQL Procedures and Functions like Oracle Packages (ish)

Oracle's package syntax is a nice way of packaging sets of functions/ procedures etc, however when a package is updated, that brings everything down. If you have a cached JDBC connection, that causes even more problems as you have to recycle the connections. On SQL, there is no package, and thus you could end up with hundreds if not thousands of little procedures and functions. A good trick is to use schemas to organize them: this example will return 2 queries; could also use input output parameters create schema [myutils]; create procedure [ myutils ].[aFewQueries] @someid int output ,@someid2 int output as begin --  set nocount on; added to prevent extra result sets from interfering with SELECT statements. set nocount on; -- Insert statements for procedure here select * from table1 where id = @someid; select * from  table2_other where  id = @someid ;  select  @someid2  = 5; end go In ColdFusion you could neatly call this ...

New Query Window in Microsoft SQL Server Management Studio Defaults/ Template

When you have those pesky common commands you have to use in almost all windows, you can change the default empty template like so Open (or wherever the installation is) C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\SqlWorkbenchProjectItems\Sql\Sqlfile.SQL And add in your defaults; my usual is: select @@SERVERNAME, @@SERVICENAME,@@VERSION, current_user, SYSTEM_USER