dbTalk Databases Forums  

SQL

comp.databases.mysql comp.databases.mysql


Discuss SQL in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Charles
 
Posts: n/a

Default SQL - 10-11-2010 , 01:06 PM






Is it possible in SQL to develop a subroutine in some way?

I've got a Java function (formula) I'd like to implement into a Select
query to compute a column, but (If I'm reading the manual correctly)
I'd rather not have to recompile the entire database and redevelop the
entire application to get a single formula included.

This will be implemented in a PHP environment and web accessible,

Anyone have any possible ideas?

Reply With Quote
  #2  
Old   
Jerry Stuckle
 
Posts: n/a

Default Re: SQL - 10-11-2010 , 02:38 PM






On 10/11/2010 2:06 PM, Charles wrote:
Quote:
Is it possible in SQL to develop a subroutine in some way?

I've got a Java function (formula) I'd like to implement into a Select
query to compute a column, but (If I'm reading the manual correctly)
I'd rather not have to recompile the entire database and redevelop the
entire application to get a single formula included.

This will be implemented in a PHP environment and web accessible,

Anyone have any possible ideas?

I don't understand your question. You don't "compile a database". But
there are MySQL functions to perform some calculations. You can also
define your own stored programs and/or functions to perform required
tasks and add them to your database.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex (AT) attglobal (DOT) net
==================

Reply With Quote
  #3  
Old   
The Natural Philosopher
 
Posts: n/a

Default Re: SQL - 10-11-2010 , 03:01 PM



Charles wrote:
Quote:
Is it possible in SQL to develop a subroutine in some way?

I've got a Java function (formula) I'd like to implement into a Select
query to compute a column, but (If I'm reading the manual correctly)
I'd rather not have to recompile the entire database and redevelop the
entire application to get a single formula included.

This will be implemented in a PHP environment and web accessible,

Anyone have any possible ideas?

http://dev.mysql.com/doc/refman/5.5/...functions.html

its not necessary to recompile the entire database engine. You can also
store user procedures and dynamically link them, it seems.

I've no idea how to go about it though. RTFM?

Reply With Quote
  #4  
Old   
Axel Schwenke
 
Posts: n/a

Default Re: SQL - 10-12-2010 , 02:09 AM



Charles <cchamb2 (AT) gmail (DOT) com> wrote:

Quote:
Is it possible in SQL to develop a subroutine in some way?
MySQL 5.0 and later supports stored routines (functions and
procedures). Those are written in some PL/SQL derivative.

Looks like you already found user defined functions (UDF)
which are written in C/C++ and typically compiled to a shared
library and loaded at runtime.

Stored routines are much easier to use!

http://dev.mysql.com/doc/refman/5.1/...-routines.html

Quote:
I've got a Java function (formula) I'd like to implement into a Select
query to compute a column
Neither way you can execute any Java code in the MySQL server.
But how complicated can that "formula" be, that you can't
express it in SQL?


XL

Reply With Quote
  #5  
Old   
Willem Bogaerts
 
Posts: n/a

Default Re: SQL - 10-12-2010 , 03:07 AM



On 11/10/10 20:06, Charles wrote:
Quote:
Is it possible in SQL to develop a subroutine in some way?

I've got a Java function (formula) I'd like to implement into a Select
query to compute a column, but (If I'm reading the manual correctly)
I'd rather not have to recompile the entire database and redevelop the
entire application to get a single formula included.

This will be implemented in a PHP environment and web accessible,

Anyone have any possible ideas?

I do not see exactly what you want. If you really want to run it on the
database server, there are a few options. In addition to the already
given suggestions, you can use prepared statements if the formula varies.

But if you just have a program that reads data from a database and
processes it, I would say that you would best apply your function after
reading in the query results, in the program and not in the query on the
database server.

Good luck,
--
Willem Bogaerts

Application smith
Kratz B.V.
http://www.kratz.nl/

Reply With Quote
  #6  
Old   
Charles
 
Posts: n/a

Default Re: SQL - 10-12-2010 , 08:04 AM



On Oct 12, 12:09*am, Axel Schwenke <axel.schwe... (AT) gmx (DOT) de> wrote:
Quote:
Charles <ccha... (AT) gmail (DOT) com> wrote:
Is it possible in SQL to develop a subroutine in some way?

MySQL 5.0 and later supports stored routines (functions and
procedures). Those are written in some PL/SQL derivative.

Looks like you already found user defined functions (UDF)
which are written in C/C++ and typically compiled to a shared
library and loaded at runtime.

Stored routines are much easier to use!

http://dev.mysql.com/doc/refman/5.1/...-routines.html

I've got a Java function (formula) I'd like to implement into a Select
query to compute a column

Neither way you can execute any Java code in the MySQL server.
But how complicated can that "formula" be, that you can't
express it in SQL?

XL
Quite.

http://www.movable-type.co.uk/script...-vincenty.html

Reply With Quote
  #7  
Old   
Charles
 
Posts: n/a

Default Re: SQL - 10-12-2010 , 08:08 AM



On Oct 12, 1:07*am, Willem Bogaerts <w.bogae... (AT) kratz (DOT) nl> wrote:
Quote:
On 11/10/10 20:06, Charles wrote:

Is it possible in SQL to develop a subroutine in some way?

I've got a Java function (formula) I'd like to implement into a Select
query to compute a column, but (If I'm reading the manual correctly)
I'd rather not have to recompile the entire database and redevelop the
entire application to get a single formula included.

This will be implemented in a PHP environment and web accessible,

Anyone have any possible ideas?

I do not see exactly what you want. If you really want to run it on the
database server, there are a few options. In addition to the already
given suggestions, you can use prepared statements if the formula varies.

But if you just have a program that reads data from a database and
processes it, I would say that you would best apply your function after
reading in the query results, in the program and not in the query on the
database server.

Good luck,
--
Willem Bogaerts

Application smith
Kratz B.V.http://www.kratz.nl/
The function I want to implement takes the GPS latitude/longtitude and
computes the distance between them.

What I'm looking for is coding so that I can:

SELECT * FROM table1 WHERE column9 = function(COL5, COL6, COL7, COL8)

and possible pass two constants as parameters so that I don't have
this problem again.

Reply With Quote
  #8  
Old   
Axel Schwenke
 
Posts: n/a

Default Re: SQL - 10-12-2010 , 08:33 AM



Charles <cchamb2 (AT) gmail (DOT) com> wrote:
Quote:
On Oct 12, 12:09=A0am, Axel Schwenke <axel.schwe... (AT) gmx (DOT) de> wrote:

http://dev.mysql.com/doc/refman/5.1/...-routines.html

Neither way you can execute any Java code in the MySQL server.
But how complicated can that "formula" be, that you can't
express it in SQL?

Quite.

http://www.movable-type.co.uk/script...-vincenty.html
1. this is not complicated
2. this can be expressed in PL/SQL
3. this is rather senseless IMHO

Quote:
What I'm looking for is coding so that I can:

SELECT * FROM table1 WHERE column9 = function(COL5, COL6, COL7, COL8)
4. comparing floating point numbers for equality is foolish

Looks like a perfect fit for a stored function. RTFM!


XL

Reply With Quote
  #9  
Old   
Sherm Pendley
 
Posts: n/a

Default Re: SQL - 10-12-2010 , 09:37 AM



Charles <cchamb2 (AT) gmail (DOT) com> writes:

Quote:
On Oct 12, 12:09Â*am, Axel Schwenke <axel.schwe... (AT) gmx (DOT) de> wrote:

But how complicated can that "formula" be, that you can't
express it in SQL?

Quite.

http://www.movable-type.co.uk/script...-vincenty.html
You're kidding, right? That's just a loop and a few calls to built-in
trig functions. It's well within the capabilities of an SQL procedure.

sherm--

--
Sherm Pendley
<http://camelbones.sourceforge.net>
Cocoa Developer

Reply With Quote
  #10  
Old   
Charles
 
Posts: n/a

Default Re: SQL - 10-12-2010 , 09:59 AM



On Oct 12, 7:37*am, Sherm Pendley <sherm.pend... (AT) gmail (DOT) com> wrote:
Quote:
Charles <ccha... (AT) gmail (DOT) com> writes:
On Oct 12, 12:09*am, Axel Schwenke <axel.schwe... (AT) gmx (DOT) de> wrote:

But how complicated can that "formula" be, that you can't
express it in SQL?

Quite.

http://www.movable-type.co.uk/script...-vincenty.html

You're kidding, right? That's just a loop and a few calls to built-in
trig functions. It's well within the capabilities of an SQL procedure.

sherm--

--
Sherm Pendley
* * * * * * * * * * * * * * * * * *<http://camelbones.sourceforge.net
Cocoa Developer
Which was the original purpose of the question - to make sure it can
be done and maybe a hint or suggestion as to direction in which to
find it.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.