Cheeky SQLServer

October 13th, 2008

sqlserver_adapter.rb in active record seems be screwin up with add_limit_offset

it’s not showin SQL Server ANY love ….

try this one, i’ve commented out some bits that didnt seem to need to be there (for me anyway… if my progs change may be I’ll need to put em back in)

p. and i’ve added the line
parts[0]=""

this strips out the table name from the ‘nested selects’ that are used to fake the offset and limit there’s gotta be a better way than this


def add_limit_offset!(sql, options)
        if options[:limit] and options[:offset]
          total_rows = @connection.select_all("SELECT count(*) as TotalRows from (#{sql.gsub(/\bSELECT(\s+DISTINCT)?\b/i, "SELECT#{$1} TOP 1000000000")}) tally")[0][:TotalRows].to_i
          if (options[:limit] + options[:offset]) >= total_rows
            options[:limit] = (total_rows - options[:offset] >= 0) ? (total_rows - options[:offset]) : 0
          end
          sql.sub!(/^\s*SELECT(\s+DISTINCT)?/i, "SELECT * FROM (SELECT TOP #{options[:limit]} * FROM (SELECT#{$1} TOP #{options[:limit] + options[:offset]} ")
          sql << ") AS tmp1" 
          if options[:order]
            options[:order] = options[:order].split(',').map do |field|
              parts = field.split(".")
              tc = parts[0]
        #      if sql =~ /\.\[/ and tc =~ /\./ # if column quoting used in query
        #        tc.gsub!(/\./, '\\.\\[')
        #        tc << '\\]'
        #      end
        #      if sql =~ /#{tc} AS (t\d_r\d\d?)/
        #        parts[0] = $1
        #      elsif parts[0] =~ /\w+\.(\w+)/
        #        parts[0] = $1
        #      end
        parts[0]="" 
              parts.join(' ')
            end.join(', ')
            sql << " ORDER BY #{change_order_direction(options[:order])}) AS tmp2 ORDER BY #{options[:order]}" 
          else
            sql << " ) AS tmp2" 
          end
        elsif sql !~ /^\s*SELECT (@@|COUNT\()/i
          sql.sub!(/^\s*SELECT(\s+DISTINCT)?/i) do
            "SELECT#{$1} TOP #{options[:limit]}" 
          end unless options[:limit].nil?
        end
      end

p. Still getting to grips with Textile … oh well p. Went to http://josephlindsay.com/archives/2005/05/27/paging-results-in-ms-sql-server/ found this snippet by Adam of http://www.esendex.com seems like a way forward I’ll try to find time to look at … hell if it works out i might even let you know


SELECT fields FROM (
SELECT TOP x * FROM (
SELECT TOP y id_field, sort_field
FROM table
WHERE conditions
ORDER sort_field ASC) as foo
ORDER by sort_field DESC) as bar
INNER JOIN table ON bar.id_field = table.id_field
ORDER by sort_field ASC

Nginx & Memcached

February 12th, 2008

http://www.igvita.com/2008/02/11/nginx-and-memcached-a-400-boost/

Servers

February 1st, 2008

I’m trying to put MONO on my server for hosting some asp.net stuff. Can i get it to work with NGINX …. not much NO

So that means turning to another server it’s apache, lighty or cherokee….. apache is BIG… limited space says look at other options first….lightt step forward…... no… step back …you’re mode rewrite sucks ..back in ya box !!!!.... ok it’s prob gonna be cherokee’s finest moment this…..i’ll let you know

Custom Config

January 21st, 2008

http://msdn2.microsoft.com/en-us/library/2tw134k3(VS.80).aspx http://www.codinghorror.com/blog/archives/000656.html http://weblogs.asp.net/dbrowning/archive/2003/03/11/3680.aspx

XPath

December 29th, 2007

XPath and Vb.net

Server Controls

December 28th, 2007

Life Cycle

NHibernate

November 8th, 2007

http://www.hibernate.org/343.html

Serializing Generics

November 7th, 2007

http://www.codeproject.com/soap/SerializationWithGenerics.asp

Dock Panel Suite

November 5th, 2007

Dock Panel Suite on SourceForge

Hats off to Weifen Luo, I’ve used this suite a couple of times and it ROCKS !!!

Generics and Collections

November 4th, 2007

  1. Which collection/list to use ?
  2. Where should I use generics?
  3. What generics are available?
    http://blogs.msdn.com/kcwalina/archive/2005/09/23/Collections.aspx

LinFu 2

November 2nd, 2007

http://www.codeproject.com/cs/library/LinFuPart2.asp
Sounds like Philip Laureano is a genius…..could be …only i haven’t had a chance to play with LinFu yet, but
  1. mixins ?
  2. ducktyping ? Sounds bllomin luvverly doesn’t it

give this a whirl http://www.codeproject.com/sqlrs/PassingArraysSQLParameter.asp

Custom Events in VB.Net

October 28th, 2007

Public NotInheritable Class ReliabilityOptimizedControl
    'Defines a list for storing the delegates
    Private EventHandlerList As New ArrayList

    'Defines the Click event using the custom event syntax.
    'The RaiseEvent always invokes the delegates asynchronously
    Public Custom Event Click As EventHandler
        AddHandler(ByVal value As EventHandler)
            EventHandlerList.Add(value)
        End AddHandler
        RemoveHandler(ByVal value As EventHandler)
            EventHandlerList.Remove(value)
        End RemoveHandler
        RaiseEvent(ByVal sender As Object, ByVal e As EventArgs)
            For Each handler As EventHandler In EventHandlerList
                If handler IsNot Nothing Then
                    handler.BeginInvoke(sender, e, Nothing, Nothing)
                End If
            Next
        End RaiseEvent
    End Event
End Class
Notice how the event is declared as Public Custom Event… this allows us to set our own delegate ‘store’ for handlers
Also see how in the raise event method we check to see if the there ARE any handlers and they are valid before calling the delegates…which means in effect we only actually raise the event if someone (or thing :-) ) is listening….
Need to see if the is a way of doing the handler check with a non-custom event

Multiple Inheritance

October 28th, 2007

The closest that vb.net get to Multipl inheritance is interfaces….but does it HAVE to end there …?

  1. dotnetJunkies Articles

Serializing Objects

October 27th, 2007

Serializing objects in VB has a few ….gotchas…

  1. When you serialize objects with events..objects that are regiestered handlers get serialized too ! CodeProject article about this

Pages


Categories


Search


ActiveRecord apache Aptana asp.net Business Objects Cache cherokee CLR collections DAL Database Debug Dev Tool dotnet Email events Gems generics GUI IE IIS lighttpd Linq Liquid MemCached Mephisto Microformats Mongrel mono Multiple Inheritance nginx Optimize orm Patterns plugins Presenter Proxy Rails Reflection Regex Rest Ruby serialization serializing server control SQLServer Standards Subsonic T-Sql testing Unit Testing UnitTesting vb vb.net VBUG xpath

Design & Maintenance by stooboo

Valid XHTML 1.1