# MS SQL triggers and ruby

**URL:** <https://rubytalk.org/t/ms-sql-triggers-and-ruby/11143>\
**Category:** ruby-talk\
**Created:** [21 April 2004 23:29 UTC](https://rubytalk.org/t/ms-sql-triggers-and-ruby/11143 "2004-04-21T23:29:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guillaume\_Marcais1](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@Guillaume\_Marcais1](https://rubytalk.org/u/Guillaume_Marcais1)\
**Post date:** [21 April 2004 23:29 UTC](https://rubytalk.org/t/ms-sql-triggers-and-ruby/11143/1 "2004-04-21T23:29:14Z")

</div>

Is there a way for a trigger in MS SQL 2000 to fire some ruby code? I  
would like to act upon the insertion of some data in the database.

Guillaume.

---

<div class="post-metadata">

**Author:** ![Shashank\_Date2](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@Shashank\_Date2](https://rubytalk.org/u/Shashank_Date2)\
**Post date:** [21 April 2004 23:59 UTC](https://rubytalk.org/t/ms-sql-triggers-and-ruby/11143/2 "2004-04-21T23:59:07Z")

</div>

“Guillaume Marcais” [guslist@free.fr](mailto:guslist@free.fr) wrote in message

> Is there a way for a trigger in MS SQL 2000 to fire some ruby code? I  
> would like to act upon the insertion of some data in the database.

Sure ! First make sure that you do not have any important table named  
RUBY\_TEST in the PUBS database and run this in Query Analyzer :

> **···**
>
> * * *
> 
> USE PUBS
> 
> IF OBJECT\_ID(‘RUBY\_TEST’,‘U’) is not NULL  
> DROP TABLE RUBY\_TEST
> 
> CREATE TABLE RUBY\_TEST(A INT)
> 
> GO
> 
> IF EXISTS (SELECT name  
> FROM sysobjects  
> WHERE name = N’trig\_test’  
> AND type = ‘TR’)  
> DROP TRIGGER trig\_test  
> GO
> 
> CREATE TRIGGER trig\_test  
> ON RUBY\_TEST  
> FOR DELETE, INSERT, UPDATE  
> AS  
> BEGIN  
> EXEC master..xp\_cmdshell ‘c:\ruby\bin\ruby -ve “puts %Q{Hello World}”’  
> END
> 
> GO
> 
> ## INSERT INTO RUBY\_TEST VALUES(20)

---

<div class="post-metadata">

**Author:** ![Guillaume\_Marcais1](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@Guillaume\_Marcais1](https://rubytalk.org/u/Guillaume_Marcais1)\
**Post date:** [22 April 2004 02:16 UTC](https://rubytalk.org/t/ms-sql-triggers-and-ruby/11143/3 "2004-04-22T02:16:26Z")

</div>

Thanx

> **···**
>
> Le 21 avr. 04, à 19:59, Shashank Date a écrit :
> 
> > “Guillaume Marcais” [guslist@free.fr](mailto:guslist@free.fr) wrote in message
> > 
> > > Is there a way for a trigger in MS SQL 2000 to fire some ruby code? I  
> > > would like to act upon the insertion of some data in the database.
> > 
> > ## Sure ! First make sure that you do not have any important table named RUBY\_TEST in the PUBS database and run this in Query Analyzer :
> > 
> > USE PUBS
> > 
> > IF OBJECT\_ID(‘RUBY\_TEST’,‘U’) is not NULL  
> > DROP TABLE RUBY\_TEST
> > 
> > CREATE TABLE RUBY\_TEST(A INT)
> > 
> > GO
> > 
> > IF EXISTS (SELECT name  
> > FROM sysobjects  
> > WHERE name = N’trig\_test’  
> > AND type = ‘TR’)  
> > DROP TRIGGER trig\_test  
> > GO
> > 
> > CREATE TRIGGER trig\_test  
> > ON RUBY\_TEST  
> > FOR DELETE, INSERT, UPDATE  
> > AS  
> > BEGIN  
> > EXEC master…xp\_cmdshell ‘c:\ruby\bin\ruby -ve “puts %Q{Hello World}”’  
> > END
> > 
> > GO
> > 
> > ## INSERT INTO RUBY\_TEST VALUES(20)

---

<div class="post-metadata">

**Author:** ![Francis\_Hwang1](https://avatars.discourse-cdn.com/v4/letter/f/ecae2f/32.png) [@Francis\_Hwang1](https://rubytalk.org/u/Francis_Hwang1)\
**Post date:** [23 April 2004 19:14 UTC](https://rubytalk.org/t/ms-sql-triggers-and-ruby/11143/4 "2004-04-23T19:14:06Z")

</div>

My object-relational mapping library Lafcadio also has triggers in it.  
You can check it out at [http://lafcadio.rubyforge.org/](http://lafcadio.rubyforge.org/) . You can write  
both pre- and post-commit triggers in Ruby code, and you can even  
write automated tests against those triggers if that’s your sort of  
thing.

Lafcadio was written first for MySQL but I know somebody who’s managed  
to make use of it with MS SQL Server.

Francis

Guillaume Marcais [guslist@free.fr](mailto:guslist@free.fr) wrote in message news:[0C60E21F-9403-11D8-88E9-003065ED1070@free.fr](mailto:0C60E21F-9403-11D8-88E9-003065ED1070@free.fr)…

> **···**
>
> > Thanx
> > 
> > Le 21 avr. 04, à 19:59, Shashank Date a écrit :
> > 
> > > “Guillaume Marcais” [guslist@free.fr](mailto:guslist@free.fr) wrote in message
> > > 
> > > > Is there a way for a trigger in MS SQL 2000 to fire some ruby code? I  
> > > > would like to act upon the insertion of some data in the database.
> > > 
> > > ## Sure ! First make sure that you do not have any important table named RUBY\_TEST in the PUBS database and run this in Query Analyzer :
> > > 
> > > USE PUBS
> > > 
> > > IF OBJECT\_ID(‘RUBY\_TEST’,‘U’) is not NULL  
> > > DROP TABLE RUBY\_TEST
> > > 
> > > CREATE TABLE RUBY\_TEST(A INT)
> > > 
> > > GO
> > > 
> > > IF EXISTS (SELECT name  
> > > FROM sysobjects  
> > > WHERE name = N’trig\_test’  
> > > AND type = ‘TR’)  
> > > DROP TRIGGER trig\_test  
> > > GO
> > > 
> > > CREATE TRIGGER trig\_test  
> > > ON RUBY\_TEST  
> > > FOR DELETE, INSERT, UPDATE  
> > > AS  
> > > BEGIN  
> > > EXEC master…xp\_cmdshell ‘c:\ruby\bin\ruby -ve “puts %Q{Hello World}”’  
> > > END
> > > 
> > > GO
> > > 
> > > ## INSERT INTO RUBY\_TEST VALUES(20)

---

<div class="post-metadata">

**Author:** ![Lothar\_Scholz2](https://avatars.discourse-cdn.com/v4/letter/l/f14d63/32.png) [@Lothar\_Scholz2](https://rubytalk.org/u/Lothar_Scholz2)\
**Post date:** [23 April 2004 19:40 UTC](https://rubytalk.org/t/ms-sql-triggers-and-ruby/11143/5 "2004-04-23T19:40:08Z")

</div>

Hello Francis,

Friday, April 23, 2004, 9:14:06 PM, you wrote:

> My object-relational mapping library Lafcadio also has triggers in it.  
> You can check it out at [http://lafcadio.rubyforge.org/](http://lafcadio.rubyforge.org/) . You can write  
> both pre- and post-commit triggers in Ruby code, and you can even  
> write automated tests against those triggers if that’s your sort of  
> thing.

> Lafcadio was written first for MySQL but I know somebody who’s managed  
> to make use of it with MS SQL Server.

And did he send you the patches ?

> **···**
>
> –  
> Best regards,  
> Lothar [mailto:mailinglists@scriptolutions.com](mailto:mailinglists@scriptolutions.com)

---

<div class="post-metadata">

**Author:** ![Francis\_Hwang1](https://avatars.discourse-cdn.com/v4/letter/f/ecae2f/32.png) [@Francis\_Hwang1](https://rubytalk.org/u/Francis_Hwang1)\
**Post date:** [24 April 2004 03:19 UTC](https://rubytalk.org/t/ms-sql-triggers-and-ruby/11143/6 "2004-04-24T03:19:06Z")

</div>

Lothar Scholz [mailinglists@scriptolutions.com](mailto:mailinglists@scriptolutions.com) wrote in message news:[893738343.20040423214225@scriptolutions.com](mailto:893738343.20040423214225@scriptolutions.com)…

> Hello Francis,
> 
> Friday, April 23, 2004, 9:14:06 PM, you wrote:
> 
> > My object-relational mapping library Lafcadio also has triggers in it.  
> > You can check it out at [http://lafcadio.rubyforge.org/](http://lafcadio.rubyforge.org/) . You can write  
> > both pre- and post-commit triggers in Ruby code, and you can even  
> > write automated tests against those triggers if that’s your sort of  
> > thing.
> 
> > Lafcadio was written first for MySQL but I know somebody who’s managed  
> > to make use of it with MS SQL Server.
> 
> And did he send you the patches ?

Well, it’s Kaspar, and he’s sent me patches for plenty of other  
things, but not for MS SQL. Which leads me to believe that at the  
level of SQL that Lafcadio uses there are no patches necessary.

FWIW, I’m very interested in supporting any DB, but I’m not certain  
exactly how to do it with MS SQL since I don’t have regular access to  
a Windows box that I could use to ensure things were working. (My  
computing life is solidly OS X and Linux these days.) I wonder how  
other project maintainers handle this sort of thing.

F.
