Implementing OOP inheritance in T-SQL (not an O/R question)

Is it possible to cleanly obtain the inheritance benefit of object-oriented programming in T-SQL? 
This is not about O/R mapping, which has been discussed to death all over the web, but rather specifically about implementing a form of inheritance in T-SQL.
Here’s why I would ask such an insane question: 
I maintain a large body of existing T-SQL that implements logic that has to be tightly tied to the database. 
It’s not heavily declarative (i.e., does not rely heavily on large monolithic SQL statements and set manipulations), because the operations that have to be carried out are by their nature sequential. 
(And imperative code can be tested in bite-size pieces, whereas huge, tight, brittle declarative SQL is difficult to maintain.) 
And I can’t rewrite it.
I’m now faced with the prospect of implementing new functionality, which will have the effect of introducing slight variations across the current
functionality.  An obvious way to implement this would be with tests and branches in every place where the functionality has to vary. 
This would spread the new functionality across the existing code in a rather unstructured way, making maintenance difficult. 
At the other extreme, I could clone the entire codebase, and make the alterations in the cloned code for the new functionality. 
At run-time, you would call into the correct code.  This would cause incredible code bloat and the attendant maintenance headaches.
Inheritance and virtual functions would solve this nicely: the common code would be placed in one class, and the parts that vary in two
other separate classes.  Alas, T-SQL does not implement inheritance.
There is a third way: 
implement virtual functions by hand in T-SQL.  At virtual function call sites, you would simply employ a lookup to determine the correct virtual function, and then call it dynamically.
 This could be easily expanded to handle a third set of logic and so on. 
It would only require modifying the entire codebase once, to insert the virtual function call points. 
The vtable of virtual functions could be stored as a table in SQL Server. 
But this sounds like an awful thing to do to future maintainers.
Has anyone else faced this situation, and how did you address it?  Does anyone know of any other approach that would mimic inheritance
in T-SQL and/or avoid the uglinesses of the above?  Thanks.

There is a third way: 
implement virtual functions by hand in T-SQL.  At virtual function call sites, you would simply employ a lookup to determine the correct virtual function, and then call it dynamically.
That can be done with
dynamic SQL.
However, there is always the ever-present performance requirement with database queries. So a fancy implementation can quickly collapse to plain in-line code stored procedure with performance benefits.
Kalman Toth Database & OLAP Architect
SQL Server 2014 Design & Programming
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

Similar Messages

  • The type must implement the inherited abstract method???

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.ActiveEvent;
    import java.applet.*;
    public class MoveIt extends Applet implements ActionListener
         private Image cup;
         private Panel keyPad;
         public int yaxis = 15;
         public int xaxis = 15;
         private Button keysArray[];
         public void init()
              cup = getImage(getDocumentBase(), "cup.gif");
              Canvas myCanvas = new Canvas();
              setBackground(Color.blue);
              setLayout(new BorderLayout());
              Button up = new Button("Up");
              Button down = new Button("Down");
              Button right = new Button("Right");
              Button left = new Button("Left");
              Button center = new Button("Center");
              add(myCanvas, BorderLayout.NORTH);
              add(keyPad, BorderLayout.SOUTH);
              keyPad.add(up, BorderLayout.NORTH);
              up.addActionListener(this);
              keyPad.add(down, BorderLayout.SOUTH);
              down.addActionListener(this);
              keyPad.add(right, BorderLayout.EAST);
              right.addActionListener(this);
              keyPad.add(left, BorderLayout.WEST);
              left.addActionListener(this);
              keyPad.add(center, BorderLayout.CENTER);
              center.addActionListener(this);
         public void paint( Graphics g )
              g.drawImage( cup, xaxis, yaxis, this );
         public void ActionPerformed(ActionEvent e)
              String action = e.getActionCommand();
              if(action.equals("Up"))
                   yaxis = yaxis - 15;
              if(action.equals("Down"))
                   yaxis = yaxis + 15;
              if(action.equals("Left"))
                   xaxis = xaxis - 15;
              if(action.equals("Right"))
                   xaxis = xaxis + 15;
              if(action.equals("Center"))
                   xaxis = 125;
                   yaxis = 60;
    }How come there is an error:
    The type MoveIt must implement the inherited abstract method
    ActionListener.actionPerformed(ActionEvent)
    What the hell does that mean?

    A class that implements an interface must define the methods of the interface. Your applet (or the one you borrowed) states at the top that it implements the ActionListener interface. If you go to the API, you'll see that this interface declares a method "actionPerformed", and so this class must have a method that matches the one in the interface. I see that your applet will have some Buttons. You'll need an actionPerformed method if you want the buttons to use your class (this) as their action listener.
    Edit: I see that you already have an "ActionPerformed" method, but note that case matters, and this is not the same as "actionPerformed". Change one letter and you're on your way.
    Edited by: Encephalopathic on Jan 15, 2008 8:44 PM

  • Iam installing 11g xe it shows Oops! Google Chrome could not connect to 127.0.0.1:8080  Try reloading the page

    iam installing 11g xe it shows Oops! Google Chrome could not connect to 127.0.0.1:8080  Try reloading the page

    Check lsnrctl services output.
    Have to have:
    database instance running
    listener running
    http presentation service in `lsnrctl services` endpoints
    Without the first two, there is no way number 3 will happen. And variations in the networking setup for the host can also prevent #3 from registering with the listener, even when #1 and #2 are working.

  • How usable is it to implement big Matrices in PL/SQL?

    Hi there,
    I'm implementing neural network Algorithms with Gradient Descend Methods in PL/SQL. The time for running the Algorithm (Backpropagation of Error) is very large - I still did my best for more Efficiency.
    Now I'm thinking about implementing another Algorithm which is called 'Levenberg Marquardt' and that is said to be much more faster. But this Algorithm handles with very large Matrices, invertes and transposes them, needs to create a Jacobian Matrix -> has a big demand for memory
    could anyone tell me how efficient it is to implement things like that in PL/SQL? Is there any use in trying it? Perhaps anybody who still worked with something like this?
    Thanks in advance
    ~Mel

    Well it's certainly possible in PL/SQL if that's the way you want to implement it...
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    type t_x is table of number index by pls_integer;
      3    type t_y is table of t_x index by pls_integer;
      4    v_xy t_y;
      5  begin
      6    for y in 1..700
      7    loop
      8      for x in 1..700
      9      loop
    10        v_xy(y)(x) := ((y-1)*700)+x;
    11      end loop;
    12    end loop;
    13    dbms_output.put_line('y size: '||v_xy.count);
    14    dbms_output.put_line('(123,567) = '||v_xy(123)(567));
    15    dbms_output.put_line('(700,700) = '||v_xy(700)(700));
    16* end;
    SQL> /
    y size: 700
    (123,567) = 85967
    (700,700) = 490000
    PL/SQL procedure successfully completed.
    SQL>

  • Data Provider implementation '/IWFND/OM_MGW_NOTIF_0001_UC' '01' 'DEFAULT' does not exist

    Hi all,
    We are trying to implement HR renewal.After installation we got the landing page for ESS and MSS. But when trying to expand chips I am getting below error message
    'Data Provider implementation '/IWFND/OM_MGW_NOTIF_0001_UC' '01' 'DEFAULT' does not exist' in the /iwfnd/error_log  transaction.
    The chips are are still blank.What could be the issue? Any one has an idea?
    Regards,
    Jay

    Hello,
    Are you using a Gateway Hub deployment? Check the setting in the "Assign SAP system Aliases to ODATA Services", and see if the services catalog service to the hub server which has LOCAL as alias and checked the default value.
    If so deactivate Default System fiag then test again.
    You can check this in SPRO:
    Regards,
    David

  • Ora-00933 sql not properly ended.

    Dear members,
    I have the following query in Report Builder 10g,
    select a, b, c
    from table1
    where a=12
    &p_whr_fy &p_whr_supp &p_whr_bt &p_whr_mat_spec &p_whr_lc_num &p_whr_cotton &P_WHR_LOC_ID
    union all
    select a, b, c
    from table2
    where a=12
    &p_whr_fy &p_whr_supp &p_whr_bt &p_whr_mat_spec &p_whr_lc_num &p_whr_cotton &P_WHR_LOC_ID
    here I used lexical parameters, and with spaces in lines its ok but when try to edit the query / remove the spaces in lines it gives the error.
    ora-00933 sql not properly ended
    Regards:

    Hi,
    Check your default values for substitution variables, at least one of them is not empty and causes an error.
    kikolus

  • Looking for gaps (SQL, not PL/SQL)

    Hi,
    This is a SQL (not PL/SQL) question.
    Let's say I have the following table:
    COLtype          COLnumber
    AA               1
    AA               2
    AA               4
    AA               5
    BB               1
    BB               2
    BB               3
    BB               5
    CC               1
    CC               5
    How do I find all gaps? I expect a result:
    COLtype          COLnumber
    AA               3
    BB               4
    CC               2
    CC               3
    CC               4
    I tried to use query:
    SELECT COLnumber + 1, COLtype FROM table a1
    WHERE NOT EXISTS (
    SELECT NULL FROM table a2
         WHERE
    a1.COLtype = a2.COLtype
    and (a2.COLnumber = a1.COLnumber + 1)
    but I received as result:
    COLtype          COLnumber
    AA               3
    AA               6
    BB               4
    BB               6
    CC               2
    CC               3
    CC               4
    CC               6
    Any other solutions, ideas?
    Thanks in advance!
    Gaspar
    Edited by: 985540 on 2013-02-01 02:59

    First let define gaps. If we have:
    COLtype COLnumber
    AA      3
    AA      4Are:
    COLtype COLnumber
    AA      1
    AA      2missing? If so is there an assumption COLnumber always starts with 1 or we just looking for gaps between existing numbers? For now I'll assume we are looking for gaps between existing numbers. Then:
    with t as (
               select  coltype,
                       colnumber,
                       lag(colnumber,1,colnumber - 1)
                         over(
                              partition by coltype
                              order by colnumber
                             ) prev_colnumber
                 from  tbl
    select  coltype,
            colnumber - column_value colnumber
      from  t,
            table(
                  cast(
                       multiset(
                                select  level
                                  from  dual
                                  connect by level < colnumber - prev_colnumber
                       as sys.OdciNumberList
      where colnumber - prev_colnumber > 1
      order by coltype,
               colnumber
    CO  COLNUMBER
    AA          3
    BB          4
    CC          2
    CC          3
    CC          4
    SQL> explain plan for
      2  with t as (
      3             select  coltype,
      4                     colnumber,
      5                     lag(colnumber,1,colnumber - 1)
      6                       over(
      7                            partition by coltype
      8                            order by colnumber
      9                           ) prev_colnumber
    10               from  tbl
    11            )
    12  select  coltype,
    13          colnumber - column_value colnumber
    14    from  t,
    15          table(
    16                cast(
    17                     multiset(
    18                              select  level
    19                                from  dual
    20                                connect by level < colnumber - prev_colnumber
    21                             )
    22                     as sys.OdciNumberList
    23                    )
    24               )
    25    where colnumber - prev_colnumber > 1
    26    order by coltype,
    27             colnumber
    28  /
    Explained.
    SQL> @?\rdbms\admin\utlxpls
    PLAN_TABLE_OUTPUT
    Plan hash value: 1739894384
    | Id  | Operation                            | Name | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                     |      | 81680 |  2552K|       |   991   (1)| 00:00:12 |
    |   1 |  SORT ORDER BY                       |      | 81680 |  2552K|  3216K|   991   (1)| 00:00:12 |
    |   2 |   NESTED LOOPS                       |      | 81680 |  2552K|       |   277   (1)| 00:00:04 |
    |*  3 |    VIEW                              |      |    10 |   300 |       |     4  (25)| 00:00:01 |
    |   4 |     WINDOW SORT                      |      |    10 |   170 |       |     4  (25)| 00:00:01 |
    |   5 |      TABLE ACCESS FULL               | TBL  |    10 |   170 |       |     3   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |   6 |    COLLECTION ITERATOR SUBQUERY FETCH|      |  8168 | 16336 |       |    27   (0)| 00:00:01 |
    |*  7 |     CONNECT BY WITHOUT FILTERING     |      |       |       |       |            |          |
    |   8 |      FAST DUAL                       |      |     1 |       |       |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       3 - filter("COLNUMBER"-"PREV_COLNUMBER">1)
       7 - filter(LEVEL<:B1-:B2)
    PLAN_TABLE_OUTPUT
    Note
       - dynamic sampling used for this statement (level=2)
    25 rows selected.
    SQL> SY.

  • I believe I have implemented it correctly but I am not receiving the notifications on my phone. I have an ad hoc provisioning profile set up.  I have the device token from the phone through NSLOG to console. I have the dot net code running without errors.

    I believe I have implemented it correctly but I am not receiving the notifications on my phone. I have an ad hoc provisioning profile set up.  I have the device token from the phone through NSLOG to console. I have the dot net code running without errors.The notifications just don’t appear.
    Any ideas where I am going wrong?

    IMAP account access by itself does not provide for syncing contacts, calendar events, and notes or anything over the air. This is possible with an Exchange account accessed via ActiveSync with the Exchange Server.
    If your company email account is an Exchange Account, your company's IT Dept. has enabled IMAP account access for your Exchange account on the Exchange server?
    If an Exchange account, the IT Dept. must have ActiveSync enabled for your account on the Exchange Server to create and access the account as an Exchange account which provides Push access for received messages, and over the air syncing for contacts and calendar events with the Exchange Server.

  • Sql not execute

    HI friends
    I am run this block but the sql not exec .
    DECLARE
    V_SQLString VARCHAR2(100) := 'select * from temp1';
    TYPE rec_temp IS RECORD
    ( V_dept dept.deptno%type ,
    V_dname dept.dname%type,
    v_loc dept.loc%type );
    V_rec rec_temp ;
    BEGIN
    select * into v_rec from dept where deptno=&values ;
    INSERT INTO temp1 VALUES ( V_rec.V_dept, V_rec.V_dname ,V_rec.v_loc);
    --DBMS_OUTPUT.PUT_LINE(      V_rec.V_dept ||' '||V_rec.V_dname ||' '||V_rec.v_loc );
    commit;
    EXECUTE IMMEDIATE  v_sqlstring ;
    END;
    plz tell me the reason
    thanks
    Edited by: abdul moyed on Jul 2, 2009 11:57 PM
    Edited by: abdul moyed on Jul 2, 2009 11:58 PM
    Edited by: abdul moyed on Jul 2, 2009 11:59 PM

    As Karthick says, if you want the results of the query you have to store them somewhere.
    example:
    SQL> set serverout on
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_sql varchar2(100) := 'select * from emp';
      3    type t_emp is table of emp%ROWTYPE;
      4    v_emp t_emp;
      5  begin
      6    execute immediate v_sql bulk collect into v_emp;
      7    for i in 1..v_emp.COUNT
      8    loop
      9      dbms_output.put_line('Emp:'||v_emp(i).empno||' - '||v_emp(i).ename);
    10    end loop;
    11* end;
    SQL> /
    Emp:7369 - SMITH
    Emp:7499 - ALLEN
    Emp:7521 - WARD
    Emp:7566 - JONES
    Emp:7654 - MARTIN
    Emp:7698 - BLAKE
    Emp:7782 - CLARK
    Emp:7788 - SCOTT
    Emp:7839 - KING
    Emp:7844 - TURNER
    Emp:7876 - ADAMS
    Emp:7900 - JAMES
    Emp:7902 - FORD
    Emp:7934 - MILLER
    PL/SQL procedure successfully completed.
    SQL>So, this example executes the query and then stores the results (bulk collected) into a variable v_emp which in itself is a PL/SQL array structure defined in the style of the expected results (emp%ROWTYPE in this case).
    One the results have been obtained into that array, you can do what you want with them by referencing the array. In my example it loops through the whole array and "displays" the employee number and name.

  • I can not purchase from the iTunes store because of the security question I am I do not know your security question and alternative mail has been hacked

    I can not purchase from the iTunes store because of the security question I am I do not know your security question and alternative mail has been hacked

    You need to contact Apple. Click here, phone them, and ask for the Account Security team.
    (87808)

  • The App Store want allow me to download new apps because I have not set up security questions.But I share an iTunes account with my friend. So if I set up the questions will my friend have to use and answer the same thing?

    The App Store want allow me to download new apps because I have not set up security questions.But I share an iTunes account with my friend. So if I set up the questions will my friend have to use and answer the same thing?

    They will have to be answered the first time when purchasing from a new computer or device.

  • HT204347 Thanks, the write-up was informative, But it do not answer for my question, that is where to look for serial # on my Macbook Pro Mid 2010 White Unibody Core 2 Duo 2.4 GHz 13.3"? Its not on bottom-case and the above article does not mention this m

    Thanks, the write-up was informative, But it do not answer for my question, that is where to look for serial # on my Macbook Pro Mid 2010 White Unibody Core 2 Duo 2.4 GHz 13.3"? Its not on bottom-case and the above article does not mention this model?

    Click on the Apple and then on about this Mac. In the new window, click on the "version 10.9.2" until you see the serial number displayed.

  • HT1911 I did not set up security question but it will not let me download anything from my new phone without answering them

    I did not set up security question but it will not let me download anything from my new phone without answering them, please help

     Account Security Team (AST) 
    Check the AppleCare number for your country here:
    http://support.apple.com/kb/HE57
    Call them up, and let them know you would like to be transferred to the Account Security Team.

  • HT201303 Hi I do not remember my security question answers, i want to change my password

    Hi I do not remember my security question answers, i want to change my password

    Hello, QJS1. 
    Thank you for visiting Apple Support Communities.
    You can reset your Apple ID password via the steps in the first article below.  I would select the option to send email verification since you do not remember the security question answers.  If you are still unable to reset this Apple ID, see the second article below.
    Apple ID: If you forget your password
    http://support.apple.com/kb/ht5787
    Apple ID: Contacting Apple for help with Apple ID account security
    http://support.apple.com/kb/HT5699
    Cheers,
    Jason H.

  • I am trying to change my password, but not remember the security questions and not access recovery email. Please give me a solution.Ana Maria Cappatto Simoes/ F. 11.50414433

    I am trying to change my password, but not remember the security questions and not access recovery email. Please give me a solution.Ana Maria Cappatto Simoes/ F. 11.50414433

    Welcome to the Apple Community.
        1.    Start here (change country if necessary) and navigate to 'Password and Security', reset your security questions using the link provided, you will receive an email to your rescue address, use the link in the email and reset your security questions.
        2.    If that doesn't help, you don't receive a reset email or you don't have a rescue address, you should contact AppleCare who will initially try to assist you with a reset email or if unsuccessful will pass you to the security team to reset your security questions for you.
        3.    If you are in a region that doesn't have international telephone support try contacting Apple through iTunes Store Support.

Maybe you are looking for

  • Macbook pro with Maverics, can't install Snow Leopard on a partition.

    I have the latest Macbook Pro with Mavericks installed.  I have partitioned the internal hard drive and wish to install snow leopard on the partition from Disk.  It will not let me run the .app and gives me the following error. "You can't use this ve

  • My BBM is not working well

    Hi, please I need A̶̲̥̅ help anytime I send A̶̲̥̅ friend request from M̶̲̥̅γ̲̣̣̥ BBM the people I sent it too will not see it but the contact will be on M̶̲̥̅γ̲̣̣̥ pending list but they send to me I can accept and chat with them what can I do to reso

  • Need help for "Numeric field Overflow" error in excel 2003.

    Hello, a friend of mine have a problem exporting Business Objects 5.1.8 to excel 2003 (turning on windows 2000). Each time she want to export her reporting in excel format (.XLS), she obtain a "Numeric field Overflow (3349)" error. So, she export in

  • Strange re-appearing alias file in Trash

    Hi guys I have a slightly bizarre question - there is an alias file that keeps appearing in my Trash called '␀␀␀õ␀␀.␀␀'. If I try to drag it out of the Trash it mystically disappears, and also if I hit command-i it also mystically disappears. Then wh

  • [Solved]-Help me swap Space key with alt gr key

    My laptop is acer 4735, the Space key was dead. I've trying swap Space key with Alt Gr key but it's not success! The Alt Gr keycode is 100 and space is 65. What's can I do now Last edited by Narga (2013-03-01 09:12:25)