* Author: Steve Lime and the MapServer team. * ****************************************************************************** * Copyright (c) 1996-2005 Regents of the University of Minnesota. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: *

* all copies of this Software or works derived from this Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. ****************************************************************************/#include "mapserver.h"

/* allocate a msDBFJoinInfo struct */joininfo=(msDBFJoinInfo*)malloc(sizeof(msDBFJoinInfo));if(!joininfo){msSetError(MS_MEMERR,"Error allocating XBase table info structure.","msDBFJoinConnect()");return(MS_FAILURE);}/* initialize any members that won't get set later on in this function */joininfo->target=NULL;joininfo->nextrecord=0;join->joininfo=joininfo;/* open the XBase file */if((joininfo->hDBF=msDBFOpen(msBuildPath3(szPath,layer->map->mappath,layer->map->shapepath,join->table),"rb"))==NULL){

/* allocate a msCSVJoinInfo struct */if((joininfo=(msCSVJoinInfo*)malloc(sizeof(msCSVJoinInfo)))==NULL){msSetError(MS_MEMERR,"Error allocating CSV table info structure.","msCSVJoinConnect()");return(MS_FAILURE);}/* initialize any members that won't get set later on in this function */joininfo->target=NULL;joininfo->nextrow=0;join->joininfo=joininfo;/* open the CSV file */if((stream=fopen(msBuildPath3(szPath,layer->map->mappath,layer->map->shapepath,join->table),"r"))==NULL){

/* once through to get the number of rows */joininfo->numrows=0;while(fgets(buffer,MS_BUFFER_LENGTH,stream)!=NULL)joininfo->numrows++;rewind(stream);if((joininfo->rows=(char***)malloc(joininfo->numrows*sizeof(char**)))==NULL){msSetError(MS_MEMERR,"Error allocating rows.","msCSVJoinConnect()");return(MS_FAILURE);}/* load the rows */i=0;

/* allocate a msMySQLJoinInfo struct */joininfo=(msMySQLJoinInfo*)malloc(sizeof(msMySQLJoinInfo));if(!joininfo){msSetError(MS_MEMERR,"Error allocating mysql table info structure.","msMySQLJoinConnect()");return(MS_FAILURE);}/* initialize any members that won't get set later on in this function */joininfo->qresult=NULL;joininfo->target=NULL;joininfo->nextrecord=0;join->joininfo=joininfo;/* open the mysql connection */if(join->connection==NULL){

}else{msSetError(MS_DBFERR,"Item %s not found in table %s.","msMySQLJoinConnect()",join->to,join->table);return(MS_FAILURE);}snprintf(qbuf,sizeof(qbuf),"EXPLAIN %s",join->table);if((joininfo->qresult=msMySQLQuery(qbuf,joininfo->conn))){/* There were some rows found, write 'em out for debug */join->numitems=mysql_affected_rows(joininfo->conn);if((join->items=(char**)malloc(sizeof(char*)*join->numitems))==NULL){msSetError(MS_MEMERR,NULL,"msMySQLJoinConnect()");return(MS_FAILURE);}MYDEBUGprintf("%d rows<br>\n",join->numitems);for(i=0;i<join->numitems;i++){MYSQL_ROWrow=mysql_fetch_row(joininfo->qresult);MYDEBUGprintf("(%s)<BR>\n",row[0]);join->items[i]=msStrdup(row[0]);}}else{msSetError(MS_DBFERR,"Item %s not found in table %s.","msMySQLJoinConnect()",join->to,join->table);return(MS_FAILURE);}joininfo->tocolumn=msStrdup(join->to);

#ifdef __NOTDEF__if(i==n){/* unable to do the join */if((join->values=(char**)malloc(sizeof(char*)*join->numitems))==NULL){msSetError(MS_MEMERR,NULL,"msMySQLJoinNext()");return(MS_FAILURE);}for(i=0;i<join->numitems;i++)