📄 process.c
字号:
return(-1); } if (res == 1) { if (cacheEntry->indices) { tableExtractValues(cacheEntry,&row, cacheEntry->def,fullFlist,query); } bcopy(row.buf, cacheEntry->row.buf, (cacheEntry->rowLen + HEADER_SIZE)); if (tableUpdateValues(cacheEntry,&row,query->fieldHead, flist) < 0) { lockGetFileLock(server,cacheEntry->dataFD, MSQL_UNLOCK); debugTrace(TRACE_OUT,"processUpdate()"); craFreeCandidate(candidate); return(-1); } /* ** Force a remap just in case the overflow file ** has been extended */ if (tableInitTable(cacheEntry,FULL_REMAP) < 0) { lockGetFileLock(server,cacheEntry->dataFD, MSQL_UNLOCK); debugTrace(TRACE_OUT,"processUpdate()"); craFreeCandidate(candidate); return(-1); } if (_checkNullFields(cacheEntry,&row,fullFlist) < 0) { bcopy(cacheEntry->row.buf, row.buf, (cacheEntry->rowLen + HEADER_SIZE)); lockGetFileLock(server,cacheEntry->dataFD, MSQL_UNLOCK); debugTrace(TRACE_OUT,"processUpdate()"); craFreeCandidate(candidate); return(-1); } if (indexCheckAllForNullFields(cacheEntry, &row, fullFlist)<0) { bcopy(cacheEntry->row.buf, row.buf, (cacheEntry->rowLen + HEADER_SIZE)); lockGetFileLock(server,cacheEntry->dataFD, MSQL_UNLOCK); debugTrace(TRACE_OUT,"processUpdate()"); craFreeCandidate(candidate); return(-1); } res = indexCheckIndices(cacheEntry, query->fieldHead, cacheEntry->def, rowNum); if (res < 0) { bcopy(cacheEntry->row.buf, row.buf, (cacheEntry->rowLen + HEADER_SIZE)); lockGetFileLock(server,cacheEntry->dataFD, MSQL_UNLOCK); craFreeCandidate(candidate); debugTrace(TRACE_OUT,"processUpdate()"); return(-1); } if (res == 0) { bcopy(cacheEntry->row.buf, row.buf, (cacheEntry->rowLen + HEADER_SIZE)); lockGetFileLock(server,cacheEntry->dataFD, MSQL_UNLOCK); strcpy(errMsg,KEY_UNIQ_ERROR); msqlDebug0(MOD_ERR, "Non unique value for unique index\n"); debugTrace(TRACE_OUT,"processUpdate()"); craFreeCandidate(candidate); return(-1); } if(tableWriteRow(cacheEntry,&row,rowNum,query) < 0) { lockGetFileLock(server,cacheEntry->dataFD, MSQL_UNLOCK); snprintf(errMsg,MAX_ERR_MSG,WRITE_ERROR, (char*)strerror(errno)); msqlDebug0(MOD_ERR,"Error on data write\n"); debugTrace(TRACE_OUT,"processUpdate()"); craFreeCandidate(candidate); return(-1); } count++; if (cacheEntry->indices) { if (indexUpdateIndices(cacheEntry, cacheEntry->def, rowNum, &row, fullFlist,&updated,candidate->index, query)<0) { lockGetFileLock(server, cacheEntry->dataFD,MSQL_UNLOCK); craFreeCandidate(candidate); return(-1); } if (updated) craResetCandidate(candidate, 1); } } rowNum = craGetCandidate(cacheEntry, candidate); } lockGetFileLock(server,cacheEntry->dataFD,MSQL_UNLOCK); snprintf(packet,PKT_LEN,"%d:\n",count); netWritePacket(query->clientSock); craFreeCandidate(candidate); debugTrace(TRACE_OUT,"processUpdate()"); return(0);}void processCreateDB(server, sock, db) msqld *server; int sock; char *db;{ char path[MSQL_PATH_LEN]; DIR *dirp; /* ** See if the directory exists */ (void)snprintf(path,MSQL_PATH_LEN,"%s/%s", server->config.dbDir, db); dirp = opendir(path); if (dirp) { closedir(dirp); snprintf(packet,PKT_LEN, "-1:Error creating database : %s exists!\n",db); netWritePacket(sock); return; } /* ** Create the directory */ if (mkdir(path,0700) < 0) { snprintf(packet,PKT_LEN, "-1:Error creating database (%s)\n", (char*)strerror(errno)); netWritePacket(sock); return; } netEndOfList(sock);}void processCopyDB(server, sock,fromDB, toDB) msqld *server; int sock; char *fromDB, *toDB;{ char fromPath[MSQL_PATH_LEN], toPath[MSQL_PATH_LEN], fromFile[MSQL_PATH_LEN], toFile[MSQL_PATH_LEN]; DIR *dirp;#ifdef HAVE_DIRENT_H struct dirent *cur;#else struct direct *cur;#endif /* ** See if the "to" directory exists */ (void)snprintf(toPath,MSQL_PATH_LEN,"%s/%s",server->config.dbDir,toDB); dirp = opendir(toPath); if (dirp) { closedir(dirp); snprintf(packet,PKT_LEN, "-1:Error copying database : %s exists!\n", toDB); netWritePacket(sock); return; } /* ** See if the "from" directory exists */ (void)snprintf(fromPath,MSQL_PATH_LEN, "%s/%s", server->config.dbDir, fromDB); dirp = opendir(fromPath); if (!dirp) { snprintf(packet, PKT_LEN, "-1:Error copying database : %s doesn't exist!\n", fromDB); netWritePacket(sock); return; } /* ** Create the directory */ if (mkdir(toPath,0700) < 0) { snprintf(packet,PKT_LEN, "-1:Error creating database (%s)\n", (char*)strerror(errno)); netWritePacket(sock); return; } /* ** Copy the files - skip '.' and '..' */ cur = readdir(dirp); cur = readdir(dirp); cur = readdir(dirp); while(cur) { snprintf(fromFile,MSQL_PATH_LEN,"%s/%s",fromPath,cur->d_name); snprintf(toFile,MSQL_PATH_LEN,"%s/%s",toPath,cur->d_name); if (tableCopyFile(fromFile, toFile) < 0) { snprintf(packet,PKT_LEN,"-1%s\n",errMsg); netWritePacket(sock); processDropDB(server,-1,toDB); return; } cur = readdir(dirp); } netEndOfList(sock);}void processMoveDB(server, sock, fromDB, toDB) msqld *server; int sock; char *fromDB, *toDB;{ char fromPath[MSQL_PATH_LEN], toPath[MSQL_PATH_LEN]; DIR *dirp; /* ** See if the "to" directory exists */ (void)snprintf(toPath,MSQL_PATH_LEN,"%s/%s",server->config.dbDir,toDB); dirp = opendir(toPath); if (dirp) { closedir(dirp); snprintf(packet,PKT_LEN, "-1:Error moving database : %s exists!\n",toDB); netWritePacket(sock); return; } /* ** See if the "from" directory exists */ (void)snprintf(fromPath,MSQL_PATH_LEN,"%s/%s", server->config.dbDir, fromDB); dirp = opendir(fromPath); if (!dirp) { snprintf(packet,PKT_LEN, "-1:Error moving database : %s doesn't exist!\n", fromDB); netWritePacket(sock); return; } closedir(dirp); /* ** Move the directory */ if (rename(fromPath, toPath) < 0) { snprintf(packet,PKT_LEN,"-1:Error moving database (%s)\n", (char*)strerror(errno)); netWritePacket(sock); return; } netEndOfList(sock); cacheInvalidateDatabase(server, fromDB);}void processDropDB(server, sock, db) msqld *server; int sock; char *db;{ char path[MSQL_PATH_LEN], filePath[255]; DIR *dirp;#ifdef HAVE_DIRENT_H struct dirent *cur;#else struct direct *cur;#endif /* ** See if the directory exists */ (void)snprintf(path,MSQL_PATH_LEN,"%s/%s", server->config.dbDir, db); dirp = opendir(path); if (!dirp) { if (sock < 0) return; snprintf(packet,PKT_LEN, "-1:Error dropping database : %s doesn't exist\n",db); netWritePacket(sock); return; } /* ** Blow away any files but dodge '.' and '..' */ cur = readdir(dirp); cur = readdir(dirp); cur = readdir(dirp); while(cur) { snprintf(filePath,MSQL_PATH_LEN,"%s/%s",path,cur->d_name); unlink(filePath); cur = readdir(dirp); } if (rmdir(path) < 0) { if (sock < 0) return; snprintf(packet,PKT_LEN,"-1:Error dropping database\n"); netWritePacket(sock); closedir(dirp); return; } closedir(dirp); if (sock >= 0) { netEndOfList(sock); } cacheInvalidateDatabase(server, db);}void processExportTable(server, sock, db, table, path, query) msqld *server; int sock; char *db, *table, *path; mQuery_t *query;{ cache_t *entry; off_t rowNum; row_t row; int fullFlist[MAX_FIELDS], fd; struct stat buf; debugTrace(TRACE_IN,"msqlExportTable()"); msqlDebug3(MOD_GENERAL,"Exporting '%s:%s' to '%s')\n",db,table,path); if((entry = tableLoadDefinition(server,table,NULL,db)) == NULL) { snprintf(packet,PKT_LEN,"-1:%s\n",errMsg); netWritePacket(sock); debugTrace(TRACE_OUT,"msqlExportTable()"); return; } if (stat(path,&buf) >= 0) { snprintf(packet,PKT_LEN, "-1:Export will not overwrite an existing file\n"); netWritePacket(sock); debugTrace(TRACE_OUT,"msqlExportTable()"); return; } fd = open(path, O_CREAT|O_TRUNC|O_RDWR, 0700); if (fd < 0) { snprintf(packet,PKT_LEN,"-1:Can't create output file\n"); netWritePacket(sock); debugTrace(TRACE_OUT,"msqlExportTable()"); return; } if (utilSetupFields(entry,fullFlist,entry->def) < 0) { snprintf(packet,PKT_LEN,"-1:%s\n",errMsg); netWritePacket(sock); debugTrace(TRACE_OUT,"msqlExportTable()"); close(fd); return; } rowNum = 0; while(rowNum != NO_POS) { if (tableReadRow(entry,&row,rowNum) < 0) { break; } if (!row.header->active) { rowNum++; continue; } tableExtractValues(entry,&row,entry->def,fullFlist,query); utilFormatExport(packet,entry->def); if (write(fd,packet,strlen(packet)) < 0) { close(fd); snprintf(packet,PKT_LEN, "-1:File write failed\n"); netWritePacket(sock); debugTrace(TRACE_OUT,"msqlExportTable()"); return; } rowNum++; } netEndOfList(sock); close(fd);}void processQuery(server, query, client, queryText) msqld *server; mQuery_t *query; int client; char *queryText;{ int res = 0; debugTrace(TRACE_IN,"processQuery()"); if (!query->curDB) { netError(query->clientSock,"No current database\n"); msqlDebug0(MOD_ERR,"No current database\n"); debugTrace(TRACE_OUT,"processQuery()"); return; } /* ** Do query logging if needed */ if (server->logFP) logQuery(server->logFP,&server->conArray[client],queryText); if (server->updateFP && query->command != MSQL_SELECT) logQuery(server->updateFP,&server->conArray[client],queryText); /* ** Process the query */ switch(query->command) { case MSQL_SELECT: if (!aclCheckPerms(READ_ACCESS)) { netError(query->clientSock,"Access Denied\n"); debugTrace(TRACE_OUT,"processQuery()"); return; } res = selectProcessSelect(server, query); break; case CREATE_TABLE: _checkWriteAccess(server); res = processCreateTable(server, query); break; case CREATE_INDEX: _checkWriteAccess(server); res = processCreateIndex(server, query); break; case CREATE_SEQUENCE: _checkWriteAccess(server); res = processCreateSequence(server, query); break; case MSQL_UPDATE: _checkWriteAccess(server); res = processUpdate(server, query); break; case MSQL_INSERT: _checkWriteAccess(server); res = processInsert(server, query); break; case MSQL_DELETE: _checkWriteAccess(server); res = processDelete(server, query); break; case DROP_TABLE: _checkWriteAccess(server); res = processDropTable(server, query); break; case DROP_INDEX: _checkWriteAccess(server); res = processDropIndex(server, query, 0); break; case DROP_SEQUENCE: _checkWriteAccess(server); res = processDropSequence(server, query); break; } if (res < 0) { netError(query->clientSock,errMsg); } debugTrace(TRACE_OUT,"processQuery()");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -