Re: ESQL/C - Retreiving Char(1)
Posted in 1997
}From ilist@rmy.emory.edu Thu Apr 17 23:19 PDT 1997 }Date: Fri, 18 Apr 1997 11:35:21 -0700 }X-Sender: bflams@uranium.bfl.soft.net }Mime-Version: 1.0 }To: informix-list@rmy.emory.edu }From: Amita Shrivastava <bflams@uranium.bfl.soft.net> }Subject: ESQL/C - Retreiving Char(1) }X-Informix-List-Id: <list.14067> } }Hi } }I have a very strange problem. I have an application which which retreives }data from a table and displays on the screen. All data is being retreived }except the data on fields which has a datatype as char(1). The application }is in ESQL/C and INFORMIX ver 4.1. This is running on AIX 4.x. } }Table is like this; } }Table truckmaster } }..... }tl_truck_type char(1) not null }.... } }I am attatching a portion of the program and header file }[...] }/* structure variables for trailer delivery */ }typedef struct } { }/* 001*/ int tlkey; /* trucklog key */ }/* 002*/ char carrier [35]; /* carrier */ }/* 003*/ char trailer_no [15]; /* trailer number */ }/* 004*/ char dflag; /* delivered flag */ }/* 005*/ char truck_type; /* truck type */ }/* 006*/ char date_empt [9]; /* date empt */ }/* 007*/ char time_empt [7]; /* time empt */ }/* 008*/ char arr_date [9]; /* arrival date */ }/* 009*/ char arr_time [7]; /* arrival time */ } } TRAILERD; }/* #endif */ OK -- what is the type of the carrier column in the database? CHAR(34) or CHAR(35)? If the database contains CHAR(34), then you have the correct declaration in the header for the carrier column, but by induction, you have the wrong type for truck_type, the CHAR(1) field. You should be using char truck_type[2]; because the C declaration needs N+1 on the array for a CHAR(N) field. If the database contains CHAR(35), then you are losing a single character on your carrier field, but this hasn't shown up as a problem because you haven't stress tested your data. And you still need to use an array of characters for the truck_type field, and it should still be of dimension 2 to avoid truncation. If you really want to use "char carrier[35];" in the C because the table says CHAR(35), then you need to use "char truck_type[1];" too. You also need to ensure that you are using CFIXCHAR type (which requires a whole lot of fiddling that your code isn't doing). Moral: all database CHAR() variables need to be stored in C char arrays. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>