short Dquery2(u_char *ret_buffer, mvar *var, int dir) { int i = -1; // dir patch flag if ((dir != 1) && (dir != -1)) // validate direction return -(ERRMLAST+ERRZ12); // complain on error if (dir == -1) // is it backwards? if ((var->key[var->slen-1] == '\0') && (var->key[var->slen-2] == '\0')) // is it a nul? { i = var->slen-2; // posn of first 0 var->key[i] = '\377'; // change to 255 } if (var->uci == UCI_IS_LOCALVAR) return ST_Query(var, ret_buffer, dir); // for local var if (var->name.var_cu[0] == '$') // ssvn? return (-ERRM38); // no such bcopy( var, &(partab.jobtab->last_ref), sizeof(var_u) + 5 + var->slen); if (i != -1) partab.jobtab->last_ref.key[i] = '\0'; // unfix from above return DB_Query(var, ret_buffer, dir, 1); // else it's global }
static unsigned Sch_SearchDocumentsInMyCoursesInDB (const char *RangeQuery) { extern const char *Txt_document_in_my_courses; extern const char *Txt_documents_in_my_courses; char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1]; MYSQL_RES *mysql_res; unsigned long NumDocs; /***** Check user's permission *****/ if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_DOCUM_IN_MY_COURSES)) /***** Split document string into words *****/ if (Sch_BuildSearchQuery (SearchQuery,"SUBSTRING_INDEX(files.Path,'/',-1)", "_latin1 "," COLLATE latin1_general_ci")) { /***** Create temporary table with codes of files in documents and shared areas accessible by me. It is necessary to speed up the second query *****/ DB_Query ("can not remove temporary table", "DROP TEMPORARY TABLE IF EXISTS my_files_crs,my_files_grp"); DB_Query ("can not create temporary table", "CREATE TEMPORARY TABLE my_files_crs" " (FilCod INT NOT NULL,UNIQUE INDEX(FilCod))" " ENGINE=MEMORY" " SELECT files.FilCod FROM crs_usr,files" " WHERE crs_usr.UsrCod=%ld" " AND crs_usr.CrsCod=files.Cod" " AND files.FileBrowser IN (%u,%u,%u,%u)", Gbl.Usrs.Me.UsrDat.UsrCod, (unsigned) Brw_ADMI_DOC_CRS, (unsigned) Brw_ADMI_TCH_CRS, (unsigned) Brw_ADMI_SHR_CRS, (unsigned) Brw_ADMI_MRK_CRS); DB_Query ("can not create temporary table", "CREATE TEMPORARY TABLE my_files_grp" " (FilCod INT NOT NULL,UNIQUE INDEX(FilCod))" " ENGINE=MEMORY" " SELECT files.FilCod FROM crs_grp_usr,files" " WHERE crs_grp_usr.UsrCod=%ld" " AND crs_grp_usr.GrpCod=files.Cod" " AND files.FileBrowser IN (%u,%u,%u,%u)", Gbl.Usrs.Me.UsrDat.UsrCod, (unsigned) Brw_ADMI_DOC_GRP, (unsigned) Brw_ADMI_TCH_GRP, (unsigned) Brw_ADMI_SHR_GRP, (unsigned) Brw_ADMI_MRK_GRP); /***** Build the query *****/ NumDocs = DB_QuerySELECT (&mysql_res,"can not get files", "SELECT * FROM " "(" "SELECT files.FilCod," "SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot," "institutions.InsCod,institutions.ShortName AS InsShortName," "centres.CtrCod,centres.ShortName AS CtrShortName," "degrees.DegCod,degrees.ShortName AS DegShortName," "courses.CrsCod,courses.ShortName AS CrsShortName," "-1 AS GrpCod" " FROM files,courses,degrees,centres,institutions,countries" " WHERE files.FilCod IN (SELECT FilCod FROM my_files_crs) AND %s" " AND files.FileBrowser IN (%u,%u,%u,%u)" " AND files.Cod=courses.CrsCod" " AND courses.DegCod=degrees.DegCod" " AND degrees.CtrCod=centres.CtrCod" " AND centres.InsCod=institutions.InsCod" " AND institutions.CtyCod=countries.CtyCod" "%s" " UNION " "SELECT files.FilCod," "SUBSTRING(files.Path,LOCATE('/',files.Path)) AS PathFromRoot," "institutions.InsCod,institutions.ShortName AS InsShortName," "centres.CtrCod,centres.ShortName AS CtrShortName," "degrees.DegCod,degrees.ShortName AS DegShortName," "courses.CrsCod,courses.ShortName AS CrsShortName," "crs_grp.GrpCod" " FROM files,crs_grp,crs_grp_types,courses,degrees,centres,institutions,countries" " WHERE files.FilCod IN (SELECT FilCod FROM my_files_grp) AND %s" " AND files.FileBrowser IN (%u,%u,%u,%u)" " AND files.Cod=crs_grp.GrpCod" " AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod" " AND crs_grp_types.CrsCod=courses.CrsCod" " AND courses.DegCod=degrees.DegCod" " AND degrees.CtrCod=centres.CtrCod" " AND centres.InsCod=institutions.InsCod" " AND institutions.CtyCod=countries.CtyCod" "%s" ") AS selected_files" " WHERE PathFromRoot<>''" " ORDER BY InsShortName,CtrShortName,DegShortName,CrsShortName,PathFromRoot", SearchQuery, (unsigned) Brw_ADMI_DOC_CRS, (unsigned) Brw_ADMI_TCH_CRS, (unsigned) Brw_ADMI_SHR_CRS, (unsigned) Brw_ADMI_MRK_CRS, RangeQuery, SearchQuery, (unsigned) Brw_ADMI_DOC_GRP, (unsigned) Brw_ADMI_TCH_GRP, (unsigned) Brw_ADMI_SHR_GRP, (unsigned) Brw_ADMI_MRK_GRP, RangeQuery); /***** List documents found *****/ Brw_ListDocsFound (&mysql_res,NumDocs, Txt_document_in_my_courses, Txt_documents_in_my_courses); /***** Drop temporary table *****/ DB_Query ("can not remove temporary table", "DROP TEMPORARY TABLE IF EXISTS my_files_crs,my_files_grp"); return (unsigned) NumDocs; } return 0; }