Re: Help: Moving ESQLC 4.10 code to ESQL 5.01
Posted in 1994
Topics: SQL Development & Query Writing, Error Codes & Troubleshooting, Connectivity: ESQL/C, 4GL & Embedded SQL
In article <2ub288$i3q@raffles.technet.sg>, Chow Keng Choon <kcchow@solomon.technet.sg> wrote: >On SCO Unix 3.2.4, if I have ESQLC 4.10 codes, can the code be use in >ESQLC 5.10 without modification? Do I have to compile my code in ESQLC >5.0 with special switches? I'm not sure if this will help, but I'll relate my conversion experience (from OnLine + ESQL/C 4.0, to OnLine + ESQL/C 5.02): There are no special switches required at compilation time. The C code should preprocess, compile, and link correctly under both environments. The syntax has apparently not changed. HOWEVER, having said that, you may want to check your code for some "gotchas" that got me, resulting in some hard-to-track logic errors. The ESQL/C libraries (and/or the database engine) must have changed slightly between 4.0 and 5.02. In particular: 1) Don't "cheat" (try to use shortcuts) in your embedded SQL. Follow the same sequence of SQL statements ($PREPARE - $DECLARE - $DESCRIBE - $OPEN ...) in every iteration. For example, there was an optimization in my code that skipped everything but the $OPEN on the second and subsequent iterations: static int first_time = 1; if(first_time) { -- format query $PREPARE object $DECLARE cursor for object $DESCRIBE select list first_time = 0; } $OPEN cursor $FETCH cursor while(sqlca.sqlcode == 0) { $FETCH cursor } $CLOSE cursor This failed like a big dog on every iteration but the first. I imagine that structures were being overwritten or re-used by the Informix code. I changed it to: if(first_time) first_time = 0; else { $FREE object; $FREE cursor; } $PREPARE object $DECLARE cursor for object $DESCRIBE [...] The $FREE is there to avoid memory leaks. If it causes problems, and if you have memory to burn, you can do without $FREE. 8^) 2) If you have C code that you call from PERFORM, and thus you build a customized version of PERFORM, it wouldn't even compile if for me. There are a couple of potential problems I can remember off the top of my head: - You can't use a database that is different from the one used by the form. In fact, you can't even make a $DATABASE statement in your code - _iqdatabase is undefined in the PERFORM link library. - You can't use a cursor in the usual way. I just used single-row $SELECT statements as a substitute. $PREPARE, $DECLARE, and $DESCRIBE (actually, their _iq... equivalents) are not defined in the PERFORM link library. There are some other incompatibilities, but I can't recall them right now. Suffice to say, if you do any serious work with PERFORM, you have a long row to hoe when converting from 4.0 to 5.X. (ACE, surprisingly, did not have the same limitations, and worked fine right out of the box.) Hope this helps. ...gwr... -- George Rapp Mail: gwr@metronet.com (home, preferred) - gwr@edsr.eds.com (work) Phone: 214/604-1036 (voice - work) 214/604-1126 (fax) Only dead fish swim with the current.