-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Saturday 25 September 2004 14:31, Rhino wrote: > ----- Original Message ----- > From: "Michael Satterwhite" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Saturday, September 25, 2004 12:29 PM > Subject: Retrieving field characteristics > > > -----BEGIN PGP SIGNED MESSAGE----- > > Hash: SHA1 > > > > In order to make my field definitions more dynamic, I'd like to retrieve > > the > > > field length definition from the database. E.g. If a field is described > > as varchar(5), I'd like to retrieve the "5" at runtime so as to limit the > > length > > > of data a user can present. > > > > Is there a way to do this using SQL? If so, how would I do this? > > A post I read the other day said that MySQL was planning to "expose its > catalog" in Version 5; I assume that means that you will be able to query > the catalog to get things like field lengths then. You can download Version > 5 and run it but I gather that very little of the Version 5 functionality > is present so far since they are still developing Version 4.1. You could > try installing Version 5 and seeing if the catalog is accessible but I > suspect it would be a wasted effort. > > There *is* one way to get the desired information TODAY (Version 4.0.x) but > you're probably not going to like it. You *can* use Java to query the > Database Metadata even in Version 4.0.x. That means you could use Java code > to determine the lengths of columns (among other things). I've tried this > and it works. Apparently, the MySQL JDBC driver can see the MySQL catalog > to get this information. That means you would have to write Java code to > get these field lengths. Interested? I didn't think so ;-)
Actually, I did figure out a way to do it in PHP (which is what I'm using). I'm assuming it would work the same in other APIs. I submitted "Describe tblname" as a query. I treated the returned data as a standard recordset and parsed the second field - which contains the type and length. Actually, writing the Java wouldn't bother me - except that this isn't a Java application. <g> Thanks for the info, though. It's good to know that when I *AM* writing Java. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFBVdf4jeziQOokQnARAtFXAJ907CkGBf/ORoSc2gayltbh7QzROgCgrTJH HWJDzMDXzkSPxHpVWGuWtQg= =lrP0 -----END PGP SIGNATURE----- -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]