Re: Registering an ESQL/C function
Posted in 1998
Pedro Antonio de Alarcon (pedro@bossa-nova.cnb.uam.es) wrote: : Does anybody know the exact steps to link a function (from its .ec : version) into a shared library?? My operating system is IRIX 6.3 and my : C compiler is cc. Unfortunately, you can't link an ESQL/C program into UDO. The technical reason for this is that the 'C' functions that ESQL/C turns into are not the same ones supported inside the engine. What is confusing is that many of the ESQL/C functions that are data type specific (dectodbl() etc) do work fine inside the engine. The second problem is that ESQL/C doesn't support some of the more sophisticated features of the ORDBMS data model (like jagged rows). 1. If your function contains no SQL call-backs (i.e. makes no SQL calls) then it should be a fairly straightforward process to follow the UDR guidelines and turn it into a .bld (shared library) file. 2. If your function does contain SQL, then making it work inside the engine is a little bit harder. You have two alternatives. a. Write a perl/'C' pre-parser that converts the EXEC SQL STUFF; into the SAPI function library. This isn't easy, but once done it would be very general. b. Re-write the function to use the SAPI interface by hand. This must be repeated for each function, but isn't really that hard once you get the hang of it. Check out http://www.informix.com/idn for more information on this. 3. It's possible that you might benefit from thinking about the problem differently. Once of the classic reasons that people use ESQL/C is because they need to do something in 'C' that isn't reasonable in SPL. Therefore, they do something like this; /* pseudo-code only */ EXEC SQL DECLARE CURSOR crs1 FOR SELECT Name, DOB, Salary FROM Emp; EXEC SQL OPEN CURSOR crs1; while(1) { EXEC SQL FETCH crs1 INTO :szName, :nDOB, :decSal; if (end_of_cursor()) break; decBonus = CalcBonus( nDob, decSal ); /* magic happens here */ EXEC SQL UPDATE Emp SET Bonus = :decBonus WHERE Name = :szName; } The 'trick' with the ORDBMS is to take the CalcBonus() function (which is probably fairly small and contains no call-backs) and put that into the server. Then the code above turns into; UPDATE Emp SET Bonus = CalcBonus( DOB, Salary); The point is that moving your application to UDO is conceptually kind of hard, but the engineering is actually easier. Hope this lot helps! KR Pb