Thread: access mysql data fields

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    22

    access mysql data fields

    Where I would run a query like below and the results is only 1 row how would I access the the individual data fields

    SELECT state, batch FROM stock WHERE serialnum = '444'

    state, batch
    1 , 003

    I have only seen examples where the code is while looped and printf'ed

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by robi View Post
    Where I would run a query like below and the results is only 1 row how would I access the the individual data fields
    I have only seen examples where the code is while looped and printf'ed
    How are you doing this (hopefully using the MySQL C API)?

    I don't know that one, but I've used the C API for sqlite, and the perl API for mysql, postgres, and sqlite. The general idea is you register a query and then you have a function to return each row in order, according to type, as you say, using a loop. If you only one want one, just get one (there may not be any others, of course). The API might have a wrapper to turn that into a single function call (get one row from a query).
    Last edited by MK27; 10-17-2011 at 12:56 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc: Template class child can't directly access parent fields
    By SevenThunders in forum C++ Programming
    Replies: 11
    Last Post: 03-17-2009, 06:05 AM
  2. new sets up incorrect data fields
    By MWAAAHAAA in forum C++ Programming
    Replies: 15
    Last Post: 07-08-2008, 02:29 PM
  3. How to send data ( fields ) to an URL?
    By AloneInTheDark in forum C# Programming
    Replies: 0
    Last Post: 02-11-2008, 07:49 PM
  4. How to access struct fields in array
    By dv007 in forum C++ Programming
    Replies: 3
    Last Post: 01-18-2006, 09:51 AM
  5. Can i use the ASP to access MYSQL database??
    By Frankiepoon in forum Windows Programming
    Replies: 1
    Last Post: 10-15-2002, 02:37 AM