Jump to content

[SOLVED] Please help, parsing


jsphp

Recommended Posts

Hi

 

I am have trouble parsing a query, I want to secretly add information to a postgresql query that identifies a user for example

 

create table test (name varchar(500))

 

becomes :

 

create table test (user_id int, name varchar(500));

 

I have attempted to do this but the best I got was searching for the opening brackets which gave the result

 

create table test (user_id int, name varchar(user_id int, 500))

 

I also have the same problem when it comes to inserting

 

if the user enters insert into test values ('000'); that is fine I just have to search for "('" however if the user types in

 

insert into test (column 1, column2) values ('000');

 

I try to parse the user_id column by identifying "(" but that will find it for both column and value which is not what I want.

 

Ideally I would like to find the nth occurance of a character and a single character followed by text e.g." (" rather than "(' " so it knows which to parse and which no to.

 

Thanks! I would be greatful to anyone who could help

Link to comment
Share on other sites

This is doable jsphp. But for best results it involves creating one preg_replace for every operation; that is one for INSERT INTO, another for CREATE TABLE, etc.

 

But before we get into the details of that, I'm pretty sure Postgre supports sophisticated logging operations schema wide (not confirmed. Just my guess). This would be a much better approach.

 

What do you think?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.