Tag Archive: sql


Should ORMs Insulate Developers from SQL?

I’ve been sick the past few days, so I have been hitting the “Stumble” button a lot on my laptop. Last night I ran across a very interesting blog post by Daniel Spiewak on his Code Commit blog:

This is a question which is fundamental to any ORM design.  And really from a philosophical standpoint, how should ORMs deal with SQL?  Isn’t the whole point of the ORM to sit between the developer and the database as an all-encompassing, object oriented layer?

read more…

What do you think?  Is he on to something?

create function ok (@boolean bit)
returns varchar(2000) as
declare @output_string varchar(2000)
select @output_string = case when @boolean = 1 then "" else "not " end
set @output_string = @output_string + "ok"
return @output_string
end

Msg 156, Level 15, State 2
Server ‘DBADEV1′, Procedure ‘ok’, Line 7
Incorrect syntax near the keyword ‘end’.
I’m trying to write an ASE implementation of TAP. A rudimentary TAP implementation for PostgreSQL is at http://www.justatheory.com/computers/databases/postgresql/introducing_pgtap.html
I’ve been able to use case in SQL UDFs before – see http://froebe.net/blog/2007/10/10/porting-mysqls-date_format-function-to-sybase-ase-1502/
Adaptive Server Enterprise/15.0.2/EBF 15654 ESD#4/P/Linux Intel/Linux 2.4.21-47.ELsmp i686/ase1502/2528/32-bit/FBO/Sat Apr 5 05:18:42 2008
I’m just missing something blindingly simple… I just know it.

From the Sybase Workspace 2.0 team:

Thursday, February 14, 2008
1:00 pm EDT / 10:00 am PDT

Join us on Valentine’s Day and you will learn how to:

  • Visually debug stored procedures and triggers
  • Visually create and edit tables, stored procedures and events
  • Navigate and manipulate database objects in the enterprise
  • Export and import database objects and services to database server

Don’t forget to sign up for the webcast! :)   Sybase will send the dial in/web address to your email so you can participate.

I’m not sure if this is the same presentation as Sybase WorkSpace for ASE:  Learn to Love SQL Development Webinar that was hosted by Samir Nigam, Director of Engineering at Sybase, last month.

Yesterday I was scratching my head on how to send an email to myself when an application failed or a certain error occurred. You see, I wanted to be able to read an email on my crackberry (Blackberry) that showed that a problem occurred and more importantly, I wanted the error messages and the snippet of code where the problem occurred.

The first part of sending the email was very simple by using Mail::Sendmail, but I wanted to extend it a bit by sending highlighted code. The problem is that the documentation of Syntax::Highlight::Engine::Kate isn’t too clear on how to use it.

The Syntax::Highlight::Engine::Kate is surprisingly easy to use once you understand that Kate just parses whatever string you give it for tokens and lets you handle how you want each type of token highlighted. In truth, you could easily forsake HTML and have it spit out XML or something else if you so desired.

package dbS::misc;
use strict;
use warnings;

our $PROC = basename($0);

BEGIN {
    use Exporter ();

    our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
    $VERSION = 1.0.0;

    @ISA = qw(Exporter);
    @EXPORT = qw(&any_to_html);
}

sub any_to_html {
    my ($type, $content) = @_;

    require Syntax::Highlight::Engine::Kate;

    my $hl = new Syntax::Highlight::Engine::Kate(
        language => $type,
        substitutions => {
            "< " => "<",
            ">" => ">",
            "&amp;" => "&amp;",
            " " => " ",
            "\\t" => "   ",
            "\\n" => "\\n",
        },
        format_table => {
            Alert => ["<span style="color: #0000ff;">", "</span>"],
            BaseN => ["<span style="color: #000000;">", "</span>"],
            BString => ["<span style="color: #00c9ff;">", "</span>"],
            Char => ["<span style="color: #00ffff;">", "</span>"],
            Comment => ["<span style="color: #007f7f;"><em>", "</em></span>"],
            DataType => ["<span style="color: #0000ff;">", "</span>"],
            DecVal => ["<span style="color: #00007f;">", "</span>"],
            Error => ["<span style="color: #00ff00;"><strong><em>", "</em></strong></span>"],
            Float => ["<span style="color: #00007f;">", "</span>"],
            Function => ["<span style="color: #000000;">", "</span>"],
            IString => ["<span style="color: #00ff00;">", ""],
            Keyword => ["</span><span style="color: #000e00;"><strong>", "</strong></span>"],
            Normal => ["", ""],
            Operator => ["<span style="color: #00ff00;">", "</span>"],
            Others => ["<span style="color: #00b060;">", "</span>"],
            RegionMarker => ["<span style="color: #0096ff;"><em>", "</em></span>"],
            Reserved => ["<span style="color: #009bff;"><strong>", "</strong></span>"],
            String => ["<span style="color: #00ff00;">", "</span>"],
            Variable => ["<span style="color: #0000ff;"><strong>", "</strong></span>"],
            Warning => ["<span style="color: #0000ff;"><strong><em>", "</em></strong></span>"],
        },
    );

    return $hl->highlightText($content);
}

1;

I wrote a wrapper subroutine for Syntax::Highlight::Engine::Kate so I can just call any_to_html(‘parsing template’, $string) and it will return HTML code.

#!/usr/bin/perl

use strict;
use warnings;

use File::Basename;
use Syntax::Highlight::Engine::Kate;

use dbS::misc;
use dbS::Sybase::Parse::SQL_File;

our $PROC = basename($0);

$|++;

my $message = "";

if ( my $sql_batch = dbS::Sybase::Parse::SQL_File::get_batch("/dbms/sybase/ASE-15_0/scripts/installmontables", undef, 1) ) {
    while (my $query = $sql_batch->next ) {
        $message .= $query;
        $message .= "go\\n\\n";
    }
} else {
    warn("unable to open the SQL file\\n");
}

print $message

The language option (a parsing template) and format_table option (token into html code) are required but the substitutions option is optional but I strongly recommend using it else the output will look odd.

The following is the output of $SYBASE/$SYBASE_ASE/scripts/installmontables using our little application. Note that we are reading the batches one by one (just because we can) even though it isn’t necessary for this example.

View full article »

Powered by WordPress | Theme: Motion by 85ideas.