ESQL/C + loc_t = Headache.
Posted in 1999
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL, Clustering, Grid & MACH11
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------ =_NextPart_001_01BE7652.AFDEE4AE Content-Type: text/plain Hi! I am currently reviewing some source that we have inherited from a subcontractor that has parted company with us. We are running Infromix Online 5.06.UC2, with ESQL/C 5.06.UC2. The system makes use of the Informix Optical and Plexus OSM to access four Cygnet jukeboxes. After reviewing some of the code (listed below), I have to admit that I am a bit confused. The main crux of the issue is that I am attempting to discover if the code below inserts the BLOB image itself or simply the descriptor information into our pages table. The documentation that I have read states that "if you set the loc_oflags field of the locator structure to LOC_DESCRIPTOR" that only the BLOB descriptor will be stored. However, the application sets loc_indicator to LOC_DESCRIPTOR instead. Is there a logical reason to do this? After reviewing the documentation, I can find no mention of setting loc_indicator to LOC_DESCRIPTOR or the value of 0x20. Can any of you tell me what this is doing? Another portion of the documentation states that if you locate BLOBS in memory that you must set loc_oflags to 0, yet after reviewing the locator.h file, I have descovered that the value of LOC_DESCRIPTOR is 0x20. Can you use loc_loctype = LOCMEMORY and loc_oflags = LOC_DESCRIPTOR together? Any assitance would be greatly appreciated. /*********************************************************************** *****/ int ReadBlobImage (char *imagefilename, loc_t *blob) { FILE *fp; struct stat sb; int ok = 0; if (debug) Log("Entering ReadBlobImage()"); if ((fp = fopen(imagefilename, "r"))) { stat(imagefilename, &sb); if ((blob->loc_buffer = (char *)malloc(sb.st_size + 1))) { ok = (fread(blob->loc_buffer, sb.st_size, 1, fp) == 1); } else blob->loc_buffer = NULL; fclose(fp); } if (ok) { blob->loc_loctype = LOCMEMORY; blob->loc_bufsize = sb.st_size; blob->loc_oflags = 0; blob->loc_size = sb.st_size; blob->loc_indicator = LOC_DESCRIPTOR; } if (debug) Log("Returning from ReadBlobImage()"); return(ok); } /*********************************************************************** *****/ /*********************************************************************** *****/ static void ProcessPages (char *imagefilename) { $loc_t blob; $int did, pnum; pages.page_hires = blob.loc_buffer = NULL; if (ReadBlobImage(imagefilename, &blob)) { did = pages.doc_id; pnum = pages.page_num; pages.page_hires = blob.loc_buffer; #ifdef DO_SQL if (debug) Log("Inserting into pages"); $INSERT INTO pages (doc_id, page_num, cluster_id, page_hires, status) VALUES ($did, $pnum, 0, $blob, 0); CHKERR(); #else printf("Insert into pages: doc_id = %d, page_num = %d\\n", did, pnum); #endif } else errsql = ERR_BADBLOB; if (pages.page_hires) free(pages.page_hires), pages.page_hires = NULL; } /*********************************************************************** *****/ Thanks. Thom ============================================ Thomas M. Farrell Client-Server Developer Raytheon Phone: (703)560-5000 ext 3091. ============================================ Fax: (703)289-1397 Please mark faxes: Attn: Thom Farrell, Client-Server Lab. ============================================ Mailing Address: Thom Farrell Raytheon Information Systems Group Mail Stop: A320 7700 Arlington Blvd Falls Church, VA 22046-1572 ============================================ ------ =_NextPart_001_01BE7652.AFDEE4AE Content-Type: text/html Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <HTML> <HEAD> <META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; = charset=3Dus-ascii"> <META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version = 5.5.1960.3"> <TITLE>ESQL/C + loc_t =3D Headache.</TITLE> </HEAD> <BODY> <P><FONT SIZE=3D2 FACE=3D"Arial">Hi!</FONT> <BR> <FONT SIZE=3D2 = FACE=3D"Arial">I am currently reviewing some source that we have = inherited from a subcontractor that has parted company with us. We are = running Infromix Online 5.06.UC2, with ESQL/C 5.06.UC2. The system = makes use of the Informix Optical and Plexus OSM to access four Cygnet = jukeboxes. After reviewing some of the code (listed below), I have to = admit that I am a bit confused. The main crux of the issue is that I am = attempting to discover if the code below inserts the BLOB image itself = or simply the descriptor information into our pages table. The = documentation that I have read states that "if you set the = loc_oflags field of the locator structure to LOC_DESCRIPTOR" that = only the BLOB descriptor will be stored. However, the application sets = loc_indicator to LOC_DESCRIPTOR instead. Is there a logical reason to = do this? After reviewing the documentation, I can find no mention of = setting loc_indicator to LOC_DESCRIPTOR or the value of 0x20. Can any = of you tell me what this is doing? Another portion of the documentation = states that if you locate BLOBS in memory that you must set loc_oflags = to 0, yet after reviewing the locator.h file, I have descovered that = the value of LOC_DESCRIPTOR is 0x20. Can you use loc_loctype =3D = LOCMEMORY and loc_oflags =3D LOC_DESCRIPTOR together? Any = assitance would be greatly appreciated.</FONT></P> <BR> <P><FONT SIZE=3D2 = FACE=3D"Arial">/********************************************************= ********************/</FONT> </P> <P><FONT SIZE=3D2 FACE=3D"Arial">int ReadBlobImage (char = *imagefilename, loc_t *blob) {</FONT> </P> <P><FONT SIZE=3D2 FACE=3D"Arial"> FILE *fp;</FONT> <BR><FONT SIZE=3D2 FACE=3D"Arial"> struct stat = sb;</FONT> <BR><FONT SIZE=3D2 FACE=3D"Arial"> int ok =3D = 0;</FONT> </P> <P><FONT SIZE=3D2 FACE=3D"Arial"> if (debug) = Log("Entering ReadBlobImage()");</FONT> <BR><FONT SIZE=3D2 FACE=3D"Arial"> if ((fp =3D = fopen(imagefilename, "r"))) {</FONT> <BR><FONT SIZE=3D2 = FACE=3D"Arial"> = stat(imagefilename, &sb);</FONT> <BR><FONT SIZE=3D2 = FACE=3D"Arial"> if = ((blob->loc_buffer =3D (char *)malloc(sb.st_size + 1))) {</FONT> <BR><FONT SIZE=3D2 = FACE=3D"Arial"> &nb= sp; ok =3D (fread(blob->loc_buffer, sb.st_size, 1, fp) =3D=
On Wed, 24 Mar 1999 19:01:51 -0500, Thom Farrell <TFarrell@fallschurch.esys.com> wrote: > I am currently reviewing some source that we have inherited from >a subcontractor that has parted company with us. We are running Infromix >Online 5.06.UC2, with ESQL/C 5.06.UC2. The system makes use of the >Informix Optical and Plexus OSM to access four Cygnet jukeboxes. After >reviewing some of the code (listed below), I have to admit that I am a >bit confused. The main crux of the issue is that I am attempting to >discover if the code below inserts the BLOB image itself or simply the >descriptor information into our pages table. The documentation that I >have read states that "if you set the loc_oflags field of the locator >structure to LOC_DESCRIPTOR" that only the BLOB descriptor will be >stored. However, the application sets loc_indicator to LOC_DESCRIPTOR >instead. Is there a logical reason to do this? After reviewing the >documentation, I can find no mention of setting loc_indicator to >LOC_DESCRIPTOR or the value of 0x20. Can any of you tell me what this is >doing? Another portion of the documentation states that if you locate >BLOBS in memory that you must set loc_oflags to 0, yet after reviewing >the locator.h file, I have descovered that the value of LOC_DESCRIPTOR >is 0x20. Can you use loc_loctype = LOCMEMORY and loc_oflags = >LOC_DESCRIPTOR together? Any assitance would be greatly appreciated. I'd venture to speculate that the person who wrote the code in question didn't know what the hell they were doing. You are pretty much right on the money in your understanding. Setting loc_indicator to LOC_DESCRIPTOR makes no sense; it is the same as any indicator value for a host variable, so a value of 32 for an insert is simply ignored (for inserts, only a value of -1 is significant). The idea behind LOC_DESCRIPTOR is that if you want many rows to point to the same blob object but only want to store one copy of that blob object, you insert it once and then select DESCR(blob_col) from that table and insert it into a new table, using LOC_DESCRIPTOR as a value for loc_oflags (you want to or it in). So yes, your blob data should be getting inserted into the table. If it were my code to maintain, I'd remove the line setting loc_indicator to LOC_DESCRIPTOR. In answer to your second question, as far as I have ever been able to tell, loc_oflags isn't really significant when dealing with blobs located in memory, except for the LOC_DESCRIPTOR value. In that case, it doesn't really matter what you have loc_loctype set to since the blob data itself is never retrieved/inserted; only the descriptor data is affected. So the combination is valid, but somewhat irrelevant. Since you have to set loc_loctype to some value, LOC_MEMORY is as good as anything. Note that the examples Informix provides in the ESQL/C product manual use this very combination. Hope this helps! Dave > > >/*********************************************************************** >*****/ > >int ReadBlobImage (char *imagefilename, loc_t *blob) { > > FILE *fp; > struct stat sb; > int ok = 0; > > if (debug) Log("Entering ReadBlobImage()"); > if ((fp = fopen(imagefilename, "r"))) { > stat(imagefilename, &sb); > if ((blob->loc_buffer = (char *)malloc(sb.st_size + 1))) { > ok = (fread(blob->loc_buffer, sb.st_size, 1, fp) == 1); > } else blob->loc_buffer = NULL; > > fclose(fp); > } > > if (ok) { > blob->loc_loctype = LOCMEMORY; > blob->loc_bufsize = sb.st_size; > blob->loc_oflags = 0; > blob->loc_size = sb.st_size; > blob->loc_indicator = LOC_DESCRIPTOR; > } > > if (debug) Log("Returning from ReadBlobImage()"); > return(ok); >} > >/*********************************************************************** >*****/ >/*********************************************************************** >*****/ > >static void ProcessPages (char *imagefilename) { > > $loc_t blob; > $int did, pnum; > > pages.page_hires = blob.loc_buffer = NULL; > if (ReadBlobImage(imagefilename, &blob)) { > did = pages.doc_id; > pnum = pages.page_num; > pages.page_hires = blob.loc_buffer; > >#ifdef DO_SQL > if (debug) Log("Inserting into pages"); > $INSERT INTO pages (doc_id, page_num, cluster_id, page_hires, >status) > VALUES ($did, $pnum, 0, $blob, 0); > CHKERR(); >#else > printf("Insert into pages: doc_id = %d, page_num = %d\\n", did, >pnum); >#endif > } else errsql = ERR_BADBLOB; > > if (pages.page_hires) free(pages.page_hires), pages.page_hires = >NULL; >}