dbTalk Databases Forums  

Preventing some SQL commands

comp.databases.postgresql.hackers comp.databases.postgresql.hackers


Discuss Preventing some SQL commands in the comp.databases.postgresql.hackers forum.



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

Default Preventing some SQL commands - 11-21-2004 , 09:55 AM






In a PL language it's sometimes desirable to prevent execution of some
commands. I would like to prevent the commands "begin [work or
transaction]", "commit", and "rollback", completely and I would like to
force the user to use explicit methods for the savepoint methods.

I wonder if there's any way to extract the nature of a command from the
execution plan returned by SPI_prepare. If not, would it be very
difficult to add? It doesn't feel optimal to add a home brewed parser
that parses the statements prior to prepare just to find out if I they
should prevented.

One approach could be to extend the CmdType enum. Perhaps something like
this:

typedef enum CmdType
{
CMD_UNKNOWN,
CMD_SELECT, /* select stmt (formerly retrieve) */
CMD_UPDATE, /* update stmt (formerly replace) */
CMD_INSERT, /* insert stmt (formerly append) */
CMD_DELETE,
CMD_TRANSACTION, /* begin, commit, rollback */
CMD_SAVEPOINT, /* savepoint, rollback to savepoint, release
savepoint */
CMD_UTILITY, /* cmds like create, destroy, copy,
* vacuum, etc. */
CMD_NOTHING /* dummy command for instead nothing
rules
* with qual */
} CmdType;

and then add a SPI function

CmdType SPI_get_command_type(void* executionPlan)

What do you think? It would certanly help PL/Java add safe and efficient
savepoint management and the other PL's are likely to share my concerns.

Regards,
Thomas Hallgren



---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: Preventing some SQL commands - 11-21-2004 , 12:35 PM






Thomas Hallgren <thhal (AT) mailblocks (DOT) com> writes:
Quote:
In a PL language it's sometimes desirable to prevent execution of some
commands. I would like to prevent the commands "begin [work or
transaction]", "commit", and "rollback", completely and I would like to
force the user to use explicit methods for the savepoint methods.
If you are executing through SPI then those operations are disallowed
already.

Quote:
I wonder if there's any way to extract the nature of a command from the
execution plan returned by SPI_prepare. If not, would it be very
difficult to add?
The main problem with this proposal is the erroneous assumption that
there can be only one command in a SPI plan.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)



Reply With Quote
  #3  
Old   
James William Pye
 
Posts: n/a

Default Re: Preventing some SQL commands - 11-21-2004 , 02:06 PM



On Sun, 2004-11-21 at 16:55 +0100, Thomas Hallgren wrote:
Quote:
In a PL language it's sometimes desirable to prevent execution of some
commands. I would like to prevent the commands "begin [work or
transaction]", "commit", and "rollback", completely and I would like to
force the user to use explicit methods for the savepoint methods.
I implemented my own SPI; not for this purpose, but I could [may] use it
for that.
This, of course, would also allow mapping specific utility commands to
my internal methods; instead of inhibiting them (tho, I don't do this
[yet, perhaps]).

Quote:
I wonder if there's any way to extract the nature of a command from the
execution plan returned by SPI_prepare. If not, would it be very
difficult to add? It doesn't feel optimal to add a home brewed parser
that parses the statements prior to prepare just to find out if I they
should prevented.
[snip]
CmdType SPI_get_command_type(void* executionPlan)
[I see Tom's reply, but considering I already wrote this; here it is
anyways.]

Hrm, I can't help but think it would be better just to allow
fetching/access to the Node tag, (e.g. T_TransactionStmt) as opposed to
creating a new command type.

NodeTag SPI_get_utility_tag(void *execPlan);

Well, something like that. I suppose it would somehow need to handle
compound queries.

Perhaps a filter operation would be a better idea.
Passing a function pointer like:

bool (*SPI_UtilityFilter) (NodeTag aStmt);
To a "void SPI_FilterUtilities(void *execPlan, SPI_UtilityFilter fp)".

Throwing an error if deemed necessary by the pointed to function.

Although, I'm inclined to think that if you require this sort of
flexibility you should probably think about writing your own SPI.


While a ways from complete/stable, my Python "SPI":
http://gborg.postgresql.org/project/...query.c?r=HEAD
http://gborg.postgresql.org/project/...ortal.c?r=HEAD

--
Regards,
James William Pye

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (FreeBSD)

iQEVAwUAQaD1KqZpiPNPvu8yAQI4kwf/TgC1NNcDyfir2Xu7taWO94oNBcGL1jBI
1zQnTdCjOlr12bS7tLzVpA3GpyCcQSaLXtcdivCbntqGo+Wq7o oZ4SnM3RoHduQs
/34iPPDq1HuThztzeL402A4PBqs6RdsXvPjQBChDQhndzh8JvZE 4+yTPTqVCzgCA
XNrsv8itbIn4OkXmnckhLWgETdBStU9ocp0JjCtOt+BeB+V4fb eS8NMUaeVSu0ch
uiJUXsH/o8KVZzOP2BQZRyCcL/vNsQKLlXqDBj7vqUCH4G5nEcwbyJ0BJhS6otac
uw94LEwvrZRGZyATDSk7+Wt0ZZwoGk0Zf0JkGI7aIKNyD71Aww mI6w==
=HSK8
-----END PGP SIGNATURE-----



Reply With Quote
  #4  
Old   
Thomas Hallgren
 
Posts: n/a

Default Re: Preventing some SQL commands - 11-21-2004 , 05:06 PM



James William Pye wrote:

Quote:
Although, I'm inclined to think that if you require this sort of
flexibility you should probably think about writing your own SPI.


I think it's far better if we all focus our efforts to improve on the
PostgreSQL SPI. That way, all PL's will benefit. That's the reason I
submitted the SPI_is_cursor_plan, SPI_getargtypeid, and SPI_getargcount
functions.

Regards,
Thomas Hallgren




---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings



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 - 2013, Jelsoft Enterprises Ltd.