Sunday, November 23, 2008    
Home My Books Blog ColdFusion About Me Back    

Calendar
<< May 2007 >>
S M T W T F S
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Search

Categories
 • Acrobat (2) [RSS]
 • Adobe (71) [RSS]
 • AdobeMAX06 (45) [RSS]
 • AdobeMAX07 (59) [RSS]
 • AdobeMAX08 (46) [RSS]
 • AIR (144) [RSS]
 • Appearances (133) [RSS]
 • Books (69) [RSS]
 • CFEclipse (14) [RSS]
 • ColdFusion (1173) [RSS]
 • Data Services (16) [RSS]
 • Fish Tank (2) [RSS]
 • Flash (108) [RSS]
 • Flex (382) [RSS]
 • Home Automation (3) [RSS]
 • Jobs (100) [RSS]
 • JRun (13) [RSS]
 • Labs (29) [RSS]
 • LiveCycle (23) [RSS]
 • MAX (181) [RSS]
 • Regular Expressions (15) [RSS]
 • RIA (12) [RSS]
 • SQL (38) [RSS]
 • Stuff (505) [RSS]
 • Tips (CF Studio) (80) [RSS]
 • Tips (CF) (795) [RSS]
 • Tips (Dreamweaver) (91) [RSS]
 • Tips (Flex Builder) (2) [RSS]
 • Using CF (140) [RSS]
 • Wireless (100) [RSS]

Other BLOGs
 • Charlie Arehart
 • Lee Brimelow
 • Ray Camden
 • Christophe Coenraets
 • Sean Corfield
 • Mihai Corlan
 • Cornel Creanga
 • John Dowdell
 • Danny Dura
 • Enrique Duvos
 • Steven Erat
 • Kevin Hoyt
 • Serge Jespers
 • Adam Lehman
 • Duane Nickull
 • Miti Pricope
 • Andrew Shorten
 • Ryan Stewart
 • James Ward
 • Greg Wilson
 • Full As A Goog

RSS Feeds
 • Feed
 • Subscribe

Join my mailing list and find out about new books and other topics of interest.

Thoughts, ideas, tips, musings, and pontifications (not necessarily in that order) by Ben Forta ...
NOTE: This is my personal blog, and the opinions and statements voiced here are my own.

Viewing By Entry / Main
May 15, 2007

Scorpio Makes Obtaining Database And Table Info Easy

This is a feature first demonstrated in CT yesterday, a new tag in Scorpio named <CFDBINFO> which does just that, it returns information about databases (and data sources, and tables, and columns, and stored procedures, and more). This first code snippet shows how to obtain a list of tables in a specified data source (using the default database):

<cfdbinfo type="tables" datasource="myDSN" name="tables">

To get column details you can do the following:

<cfdbinfo type="columns" datasource="myDSN" table="myTables" name="columns">

This would return a query containing column names, type, size, default values, whether it allows NULL values, key associations, and more.

As you can see, <CFDBINFO> accepts a TYPE attribute which tells it what information you want, and the following types are supported:

  • columns: Returns column details for a specific table.
  • dbnames: Returns the databases in a specified data source.
  • foreignkeys: Returns foreign key name information, including associated primary key, and delete and update rules.
  • index: Returns index specifics, including column details, page usage, and whether or not the index is unique.
  • procedures: Returns available stored procedures.
  • tables: Returns the names of tables within a specific database.
  • version: Returns database drive version details.

TrackBacks
There are no trackbacks for this entry.

No trackback URL. Trackbacks are only allowed via interactive form.

Comments
ORLY?

You need to talk to Tim and Adam, mate :)
# Posted By Critter | 5/16/07 11:09 AM
Would love to see a cfdump of the type="columns" version of the tag call. Any chance you could post it?
# Posted By Kurt Bonnet | 5/16/07 1:53 PM
Technically, Tim and Adam didn't DEMONSTRATE the tag so I guess Ben is technically correct, though we in sunny north carolina were the first non-NDA people to be told about it =)

nyaa nyaa CT!
# Posted By Rick Root | 5/16/07 2:39 PM
What level of db permissions will be needed for this tag to work?
# Posted By jeff | 5/16/07 2:52 PM
re: level of DB perms -

My hunch is that the data in question can be selected from system tables that are kept for each DB (like the properties tables that MS SQL SERVER maintains for each DB).

So if the db user in question can select on those system tables, that will probably do it...

In an example setup, you might have a ms sql server DB named "myDB" and then a sql login w/username "MyDB-pubUser" with access permitted on that DB, with the roles of public and data-reader. data-reader would probably include the necessary SELECT rights on the sys tables, to allow this kind of introspection.

Then you'd just add the credentials for MyDB-pubUser on the datasource.

how this is accomplished with other RDBMS systems I can't say for sure; but consider in the good old days, running a "DESCRIBE" on a table or other object; my point being that the support for this kind of thing on the part of the RDBMS has been been around for some time.

Again this is just my hunch; there could be other equally tennable ways to get at the info. in question - i.e. maybe just using special SQL aggregate functions or the like.
# Posted By Jay | 5/16/07 3:52 PM
Critter, Rick, nope - your event was an evening event, right? CT had too events that same day, a lunch time one and an evening one. So, I believe CT was indeed first. ;-)

Jeff, whatever permissions the data source has is what are used. Usually, DBMSs show you this information based on what your login has access to.

--- Ben
# Posted By Ben Forta | 5/16/07 4:49 PM
Well then, Tim and Adam LIED TO US!

I feel so used.
# Posted By Rick Root | 5/16/07 5:53 PM
Here is a sample output for columns:

CHAR_OCTET_LENGTH    COLUMN_DEFAULT_VALUE    COLUMN_NAME    COLUMN_SIZE    DECIMAL_DIGITS    IS_FOREIGNKEY    IS_NULLABLE    IS_PRIMARYKEY    ORDINAL_POSITION    REFERENCED_PRIMARYKEY    REFERENCED_PRIMARYKEY_TABLE    REMARKS    TYPE_NAME
1    0    [empty string]    id    10    0    NO    NO    YES    1    N/A    N/A    [empty string]    int identity
# Posted By Shaun | 5/16/07 7:15 PM
Nice bit of functionality.

But why - O WHY - was it implemented as a tag (as opposed to a function, I mean)?

Sigh.

--
Adam
# Posted By Adam Cameron | 5/17/07 5:49 AM

  © Copyright 1997-2008 Ben Forta, All Rights Reserved