SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:That code should never be used in any production environment without any validation of the parameter. Right now it's highly susceptible to SQL injection.
Tarun Bolla wrote:
Rob Spoor wrote:That code should never be used in any production environment without any validation of the parameter. Right now it's highly susceptible to SQL injection.
Yeah...I concentrated on the logic but security measure can be taken. Basically with this small req the parameter validation would be like (using a regular expression)
or more specifically
Martin Vajsar wrote:Or even better, checking the user supplied table/column names against a list of known tables/columns. I would not opt for anything less
Tarun Bolla wrote:
Tarun Bolla wrote:
Martin Vajsar wrote:Or even better, checking the user supplied table/column names against a list of known tables/columns. I would not opt for anything less
Thats what the below quote is about....
Tarun Bolla wrote:
Tarun Bolla wrote:Here is an example...
Consider three tables as below
User --> UserID, Name, Age, Sex
Account --> AccountID, UserID, Balance, Type
Transaction --> TransactionID, AccountID, Amount, Type
Now if the user wants to see User.Name, Account.Balance, Transaction.Amount, Transaction.Type
Here is a sample code..considering the parameter will be like User.Name-Account.Balance-Transaction.Amount-Transaction.Type (You can use any other separator according to your wish)
You need to refine this code a bit to suit your req..but i hope this will give you a start
Gaurav Chander wrote: there are about 14 tables so I'm not sure how to handle this.
Tarun Bolla wrote:
Gaurav Chander wrote: there are about 14 tables so I'm not sure how to handle this.
That can be made easier with UI design. Consider this design
1. You need 2 dropdowns with all the tables(filled initially), columns(not filled initially)
2. When ever the selected table changes, columns drop down populates with respective columns
3. And you can provide a button like "Select this"
4. When user clicks on the button you can concatenate the TABLENAME.COLUMNNAME to another list in UI showing the user that he has opted to select those
5. When the user clicks submit, you will build the concatenated string from the list on client side and send it to server to build the query on server side
This way you need not worry about 14 or 40 tables
Tarun Bolla wrote:
Gaurav Chander wrote: there are about 14 tables so I'm not sure how to handle this.
That can be made easier with UI design. Consider this design
1. You need 2 dropdowns with all the tables(filled initially), columns(not filled initially)
2. When ever the selected table changes, columns drop down populates with respective columns
3. And you can provide a button like "Select this"
4. When user clicks on the button you can concatenate the TABLENAME.COLUMNNAME to another list in UI showing the user that he has opted to select those
5. When the user clicks submit, you will build the concatenated string from the list on client side and send it to server to build the query on server side
This way you need not worry about 14 or 40 tables
Wendy Gibbons wrote:This doesn't in any way address the joins between the tables, if he has 40 tables he will need to store somewhere all of the primary keys between the tables, and the foriegn keys between the tables.
Tarun Bolla wrote:
Wendy Gibbons wrote:This doesn't in any way address the joins between the tables, if he has 40 tables he will need to store somewhere all of the primary keys between the tables, and the foriegn keys between the tables.
My apologies to the OP. I was under a perception that all the tables carry single join column. It seems like a bigger picture now and a good problem to solve. See you soon.(with another solution ofcourse)
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |