473,385 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

PHP and PostgreSQL question on identifier limits.

Hello,

I am migrating from MySQL to PostgreSQL and ran into a limitation of
PostgreSQL. I ran into this because of a technique I use for displaying
results of a SELECT query. In some cases I like to have the heading of some
columns in the table be clickable, usually to sort output by that column.

I have common a function I use that displays the results of a query in an HTML
table with the column headings being the field names. Here is a snippet of
code showing a typical query:

================================================== =====
$_GET['sort'] && $_SESSION['sort']=$_GET['sort'];
$sort=$_SESSION['sort'];
$sort || $sort="field1";

$query="SELECT
field1 AS \"<a href=$PHP_SELF?sort=field1>field1</a>\",
field2 AS \"<a href=$PHP_SELF?sort=field2>field2</a>\",
field3 AS \"<a href=$PHP_SELF?sort=userid>field3</a>\"
FROM my_table ORDER BY $sort";

$tbl=new Table($query);
$tbl->print();
================================================== =====

The problem I ran into is when the "AS" exceeds 63 characters --- which it
does NOT in the above example, but sometimes DOES in more complex real-life
queries. In those cases I get a PostgreSQL error saying that the identifier
is too long. Looking at the PostgreSQL documentation I see this is set to 63
characters by default but can be changed with a recompile.

Before I recompile PostgreSQL I would like to re-think my strategy for making
column headings clickable links.

Does anyone else create HTML tables with clickable headers? If so, do you use
a similar or different technique?

--
Robert C. Paulsen, Jr.
ro****@paulsenonline.net

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #1
2 1291
Hi,
$_GET['sort'] && $_SESSION['sort']=$_GET['sort'];
$sort=$_SESSION['sort'];
$sort || $sort="field1";
First of all I don't feel very comfortable with this exotic syntax, but
this is not the right place to discuss about it ;)

$query="SELECT
field1 AS \"<a href=$PHP_SELF?sort=field1>field1</a>\",
field2 AS \"<a href=$PHP_SELF?sort=field2>field2</a>\",
field3 AS \"<a href=$PHP_SELF?sort=userid>field3</a>\"
FROM my_table ORDER BY $sort";

$tbl=new Table($query);
$tbl->print();


Is there a good reason why you don't add hyperlinks inside your Table
class, instead than using column names for such a purpose?
P.S.
Handling column sorting like you're doing is a big security risk! I hope
you are doing some more checks on $sort, otherwise SQL injection attacks
would be very easy to do.
Best regards
--
Matteo Beccati
http://phpadsnew.com/
http://phppgads.com/

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #2
On Sunday 15 August 2004 06:58 pm, Matteo Beccati wrote:
Hi,
$_GET['sort'] && $_SESSION['sort']=$_GET['sort'];
$sort=$_SESSION['sort'];
$sort || $sort="field1";
First of all I don't feel very comfortable with this exotic syntax, but
this is not the right place to discuss about it ;)


I guess "exotic" depends on your background.
$query="SELECT
field1 AS \"<a href=$PHP_SELF?sort=field1>field1</a>\",
field2 AS \"<a href=$PHP_SELF?sort=field2>field2</a>\",
field3 AS \"<a href=$PHP_SELF?sort=userid>field3</a>\"
FROM my_table ORDER BY $sort";

$tbl=new Table($query);
$tbl->print();


Is there a good reason why you don't add hyperlinks inside your Table
class, instead than using column names for such a purpose?


That might be the best solution. This code has evolved from a time before I
was using classes. Used to be a simple function call. With classes I could
add the ability to assign links to the headers.


P.S.
Handling column sorting like you're doing is a big security risk! I hope
you are doing some more checks on $sort, otherwise SQL injection attacks
would be very easy to do.


Good point. Using your suggestion about implementing this inside the Table
class will make this easier to control.

--
Robert C. Paulsen, Jr.
ro****@paulsenonline.net

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bill Kratzer | last post by:
Hi... I am currently working on a Java-based product that is backed by PostgreSQL (among other databases). I have noticed that PostgreSQL appears to truncate column alias names after 31...
2
by: Thomas Köhler | last post by:
Hi, Just having read http://developer.postgresql.org/todo.php - seems like quite a few features for high availibility are still missing. So - what's the recommended way to get some kind of HA up...
25
by: Bo Lorentsen | last post by:
Hi .. Well after discussing how bugs are handled in PG, and the development culture in both MySQL and Postgresql, my boss agress that it may be a good aletenertive til MySQL 4.x (InnoDB), but...
29
by: Paul Ganainm | last post by:
Hi all, Following up on another thread, here is a comparison between FB and PG from an FB'ers POV. BTW, FB is the love-child of Open-Source-Interbase. BTW, I have tried to be as accurate as I...
4
by: Chris Travers | last post by:
Hi all; A few years ago, I set about porting a PHP application from MySQL to PostgreSQL, after realizing that MySQL wasn't going to be able to handle it. In order to do this, I built a light,...
46
by: James Harris | last post by:
Before I embark on a new long-term project I'd appreciate your advice on how to split up long names. I would like to keep the standards for command names the same as that for variable names....
4
by: Ying Lu | last post by:
Hello, I have a table named "USER" under MySQL database. When I am trying to move tables from MySQL to PostgreSQL, I found that I could not create a table namely "USER". I guess "USER" is a key...
9
by: Jacques Lebastard | last post by:
I have a problem writing PHP ODBC scripts that suit both MySQL and PostgreSQL. So far, the following syntaxes seem to apply to each database (this is an 'insert' example; the same differences apply...
3
by: David T. Ashley | last post by:
I have this ugly habit of prefixing all function and variable names with some identifying information about the owning module and perhaps also the subcategory of function, i.e. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.