Practices
  Home arrow Practices arrow Page 3 - Database Independent Development in C
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PRACTICES

Database Independent Development in C
By: Clay Dowling
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 10
    2004-09-27

    Table of Contents:
  • Database Independent Development in C
  • Making the Connection
  • Getting Results
  • An Example
  • Extending libdbi

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Database Independent Development in C - Getting Results


    (Page 3 of 5 )

    Once a connection has been established, dbi_conn_query() lets you make a query into the database. dbi_conn_query takes the connection as the first argument and a printf formatted SQL statement as its second argument. The remainder is the standard variable argument list. It is worth noting that at this time the arguments are in no way run through any kind of string escaping function. It's the duty of the programmer to escape any input. The native escaping function of the database library can be obtained with a little work, although at times I have written my own string escaping function.

    The return value from dbi_conn_query() is a dbi_result object. You cycle through the result set by using the dbi_result_next_row() function, which takes the result set as its only argument. This function must be called at least once before any actual column results can be extracted. This function returns 0 if there are no more rows in the result set.

    To get the values of individual columns, there are a variety of dbi_result_get_datatype functions which take the dbi_result object and the column name as parameters. The most common are dbi_result_get_long and dbi_result_get_string, but they exist for every common data type, including datetime columns (which return a time_t).

    Finally, when you are done with the result set and the connection, there are a few cleanup functions. dbi_result_free() frees up the memory used by the result set. dbi_conn_close() will close the database connection, and dbi_shutdown() unloads the database drivers that have been loaded.

    More Practices Articles
    More By Clay Dowling


     

       

    PRACTICES ARTICLES

    - More Techniques for Finding Things
    - Finding Things
    - Finishing the System`s Outlines
    - The System in So Many Words
    - Basic Data Types and Calculations
    - What`s the Address? Pointers
    - Design with ArgoUML
    - Pragmatic Guidelines: Diagrams That Work
    - Five-Step UML: OOAD for Short Attention Span...
    - Five-Step UML: OOAD for Short Attention Span...
    - Introducing UML: Object-Oriented Analysis an...
    - Class and Object Diagrams
    - Class Relationships
    - Classes
    - Basic Ideas





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway