static void BufferedWriterDumpParams(BufferedWriter *self) { char *str; StringInfoData buf; initStringInfo(&buf); appendStringInfoString(&buf, "WRITER = BUFFERED\n"); str = QuoteString(self->base.dup_badfile); appendStringInfo(&buf, "DUPLICATE_BADFILE = %s\n", str); pfree(str); if (self->base.max_dup_errors == INT64_MAX) appendStringInfo(&buf, "DUPLICATE_ERRORS = INFINITE\n"); else appendStringInfo(&buf, "DUPLICATE_ERRORS = " int64_FMT "\n", self->base.max_dup_errors); appendStringInfo(&buf, "ON_DUPLICATE_KEEP = %s\n", ON_DUPLICATE_NAMES[self->base.on_duplicate]); appendStringInfo(&buf, "TRUNCATE = %s\n", self->base.truncate ? "YES" : "NO"); LoggerLog(INFO, buf.data, 0); pfree(buf.data); }
void ReaderDumpParams(Reader *self) { char *str; StringInfoData buf; initStringInfo(&buf); str = QuoteString(self->infile); appendStringInfo(&buf, "INPUT = %s\n", str); pfree(str); str = QuoteString(self->parse_badfile); appendStringInfo(&buf, "PARSE_BADFILE = %s\n", str); pfree(str); str = QuoteString(self->logfile); appendStringInfo(&buf, "LOGFILE = %s\n", str); pfree(str); if (self->limit == INT64_MAX) appendStringInfo(&buf, "LIMIT = INFINITE\n"); else appendStringInfo(&buf, "LIMIT = " int64_FMT "\n", self->limit); if (self->max_parse_errors == INT64_MAX) appendStringInfo(&buf, "PARSE_ERRORS = INFINITE\n"); else appendStringInfo(&buf, "PARSE_ERRORS = " int64_FMT "\n", self->max_parse_errors); if (PG_VALID_FE_ENCODING(self->checker.encoding)) appendStringInfo(&buf, "ENCODING = %s\n", pg_encoding_to_char(self->checker.encoding)); appendStringInfo(&buf, "CHECK_CONSTRAINTS = %s\n", self->checker.check_constraints ? "YES" : "NO"); LoggerLog(INFO, buf.data); pfree(buf.data); ParserDumpParams(self->parser); }
/* PrettyCmd( path, cmd, opts ) Returns a command string that could be used on the command line */ string ProcessUtil::PrettyCmd( const string &path, const string &cmd, const vector<string> &opts ) { #ifdef WIN32 string command = QuoteString( path + string("\\") + cmd ); for( int i = 0; i < opts.size(); i++ ) { command += string(" ") + QuoteString( opts[i] ); } #else string command = path + string("/") + cmd; for( unsigned int i = 0; i < opts.size(); i++ ) { command += string(" ") + opts[i]; } #endif //add line feed ending command += string("\n"); return command; }
void WriterDumpParams(Writer *self) { char *str; StringInfoData buf; initStringInfo(&buf); str = QuoteString(self->output); appendStringInfo(&buf, "OUTPUT = %s\n", str); pfree(str); appendStringInfo(&buf, "MULTI_PROCESS = %s\n", self->multi_process ? "YES" : "NO"); appendStringInfo(&buf, "VERBOSE = %s\n", self->verbose ? "YES" : "NO"); LoggerLog(INFO, buf.data, 0); pfree(buf.data); self->dumpParams(self); }
void Browse_Organization::UpdateFunc() { QSqlQuery Query(Global.DataBase); QString SearchString = QuoteString(FilterBy->text().trimmed()); QString Where = ""; QString QueryString; QStringList SearchList; Where = SearchPrepare( " POSITION (LOWER(?) IN LOWER(o.\"Name\")) > 0 OR " " POSITION (LOWER(?) IN LOWER(o.\"Phone\")) > 0 OR " " POSITION (LOWER(?) IN LOWER(o.\"Contact\")) > 0 ", &SearchList, SearchString); QueryString = "SELECT * " "FROM public.\"Organization\" AS o " + Where+ OrderBy; Query.prepare(QueryString); SearchBind(SearchList,&Query,3); if (!Query.exec()) { GuiSqlError("Ошибка при работе с БД!"); return; } Model->setQuery(Query); Model->setHeaderData(1,Qt::Horizontal,tr("Наименование")); Model->setHeaderData(2,Qt::Horizontal,tr("Телефон")); Model->setHeaderData(4,Qt::Horizontal,tr("Контактное лицо")); Table->setModel(Model); Table->setColumnHidden(0,true); Table->setColumnHidden(3,true); Table->setColumnHidden(5,true); TuneTable(Table); Table->resizeColumnsToContents(); Table->horizontalHeader()->setSectionResizeMode(1,QHeaderView::Stretch); Table->setSortingEnabled(true); Table->horizontalHeader()->setSortIndicator(SortColumn, SortOrder); connect(Table->selectionModel(),SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),this,SLOT(SlotCurChanged(QModelIndex,QModelIndex))); int SelRow = FindRow((QSqlQueryModel*)(Table->model()),Cur); Table->selectRow(SelRow); }
void AddImgToList(char** strp, char* str) { str = QuoteString(str); if (*strp) { int newsize = strlen(*strp) + strlen(str) + 2; char* newstr = malloc(newsize); if (!newstr) { free(str); *strp = 0; return; } snprintf(newstr, newsize, "%s %s", *strp, str); free(*strp); *strp = newstr; } else *strp = strdup(str); /* QuoteString allocated a copy, so free that now: */ free(str); }
/** * Create a quoted command from a list of arguments. The returned string * is allocated with "malloc" and should be "free"d. * * argv is UTF8 */ static PRUnichar* MakeCommandLine(int argc, PRUnichar **argv) { int i; int len = 1; // null-termination for (i = 0; i < argc; ++i) len += QuotedStrLen(argv[i]) + 1; PRUnichar *s = (PRUnichar*) malloc(len * sizeof(PRUnichar)); if (!s) return NULL; PRUnichar *c = s; for (i = 0; i < argc; ++i) { c = QuoteString(c, argv[i]); *c = ' '; ++c; } *c = '\0'; return s; }
void Browse_User::UpdateFunc() { QSqlQuery Query(Global.DataBase); QString SearchString = QuoteString(FilterBy->text().trimmed()); QString Where = ""; QString QueryString; QStringList SearchList; if (Mode == buWidget) { Where = SearchPrepare( " POSITION (LOWER(?) IN LOWER(f.\"Name\")) > 0 OR " " POSITION (LOWER(?) IN LOWER(f.\"Role\")) > 0 OR " " POSITION (LOWER(?) IN LOWER(to_char(f.\"StartDate\"::date ,'DD.MM.YYYY' ))) > 0 OR " " POSITION (LOWER(?) IN LOWER(f.\"StopDate\")) > 0 OR " " POSITION (LOWER(?) IN LOWER(f.\"Position\")) > 0 ", &SearchList, SearchString); QString QueryString = "SELECT * FROM (" " SELECT " " u.\"Id\" AS \"Id\", " " u.\"Name\" AS \"Name\", " " COALESCE(r.\"Name\",'-') AS \"Role\", " " u.\"StartDate\" AS \"StartDate\", " " CASE WHEN (u.\"StopDate\" = to_date('1980-01-01', 'YYYY-MM-DD')) THEN 'в штате' ELSE to_char(u.\"StopDate\",'DD-MM-YYYY') END AS \"StopDate\", " " COALESCE(d.\"Name\",'-') AS \"Position\", " " u.\"LongName\" AS \"LongName\" " " FROM public.\"Users\" as u " " LEFT OUTER JOIN public.\"Rubricator\" AS r ON (r.\"GroupId\" = 1 AND r.\"Id\" = u.\"Role\") " " LEFT OUTER JOIN public.\"Rubricator\" AS d ON (d.\"GroupId\" = 2 AND d.\"Id\" = u.\"Position\") " " GROUP BY u.\"Id\", r.\"Name\", d.\"Name\" " ") AS f " +Where +OrderBy; Query.prepare(QueryString); SearchBind(SearchList,&Query,5); if (!Query.exec()) { GuiSqlError("Ошибка при работе с БД!"); return; } Model->setQuery(Query); Model->setHeaderData(0,Qt::Horizontal,tr("Ид")); Model->setHeaderData(1,Qt::Horizontal,tr("ФИО")); Model->setHeaderData(2,Qt::Horizontal,tr("Права")); Model->setHeaderData(3,Qt::Horizontal,tr("Прием")); Model->setHeaderData(4,Qt::Horizontal,tr("Увольнение")); Model->setHeaderData(5,Qt::Horizontal,tr("Подразделение")); Model->setHeaderData(6,Qt::Horizontal,tr("ФИО(полностью)")); Table->setModel(Model); Table->setItemDelegate(new NotEditableDelegate()); Table->setColumnHidden(0,true); Table->setColumnHidden(6,true); TuneTable(Table); Table->setSortingEnabled(true); Table->horizontalHeader()->setSortIndicator(SortColumn, SortOrder); Table->resizeColumnsToContents(); Table->horizontalHeader()->setSectionResizeMode(1,QHeaderView::Stretch); } if (Mode == buService) { Where = SearchPrepare( " POSITION (LOWER(?) IN LOWER(f.\"Name\")) > 0", &SearchList, SearchString); QueryString = "SELECT * FROM ( " " SELECT u.\"Id\" AS \"Id\", " " u.\"Name\" AS \"Name\" " " FROM public.\"Users\" AS u, public.\"Service2Users\" AS s " " WHERE u.\"Id\" = s.\"User\" AND s.\"Service\" ="+(*Ref)["Id"].toString()+" " ") AS f " +Where +OrderBy; Query.prepare(QueryString); SearchBind(SearchList,&Query,1); if (!Query.exec()) { GuiSqlError("Ошибка при работе с БД!"); return; } Model->setQuery(Query); Model->setHeaderData(0,Qt::Horizontal,tr("Ид")); Model->setHeaderData(1,Qt::Horizontal,tr("ФИО")); Table->setModel(Model); Table->setColumnHidden(0,true); TuneTable(Table); Table->setSortingEnabled(true); Table->horizontalHeader()->setSortIndicator(SortColumn, SortOrder); Table->resizeColumnsToContents(); Table->horizontalHeader()->setSectionResizeMode(1,QHeaderView::Stretch); } if (Mode == buSelect) { Where = SearchPrepare( " POSITION (LOWER(?) IN LOWER(f.\"Name\")) > 0", &SearchList, SearchString); QueryString = " SELECT * FROM ( " " SELECT u.\"Id\", u.\"Name\" FROM public.\"Users\" AS u " " WHERE u.\"Id\" NOT IN ( " " SELECT u1.\"Id\" FROM public.\"Users\" AS u1, public.\"Service2Users\" AS s " " WHERE s.\"Service\" = 1 AND s.\"User\" = u1.\"Id\" " " )) AS f " +Where +OrderBy; Query.prepare(QueryString); SearchBind(SearchList,&Query,1); if (!Query.exec()) { GuiSqlError("Ошибка при работе с БД!"); return; } Model->setQuery(Query); Model->setHeaderData(0,Qt::Horizontal,tr("Ид")); Model->setHeaderData(1,Qt::Horizontal,tr("ФИО")); Table->setModel(Model); Table->setColumnHidden(0,true); TuneTable(Table); Table->setSortingEnabled(true); Table->horizontalHeader()->setSortIndicator(SortColumn, SortOrder); Table->resizeColumnsToContents(); Table->horizontalHeader()->setSectionResizeMode(1,QHeaderView::Stretch); } connect(Table->selectionModel(),SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),this,SLOT(SlotCurChanged(QModelIndex,QModelIndex))); int SelRow = FindRow((QSqlQueryModel*)(Table->model()),Cur); Table->selectRow(SelRow); }
int ProcessUtil::ForkCmd( const string &path, const string &cmd, const vector<string> &opts ) { #ifdef WIN32 SECURITY_ATTRIBUTES saAttr; saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); saAttr.bInheritHandle = TRUE; saAttr.lpSecurityDescriptor = NULL; if ( !CreatePipe( &m_StdoutPipe[PIPE_READ], &m_StdoutPipe[PIPE_WRITE], &saAttr, 0 ) ) { printf( "Error StdoutRd CreatePipe\n" ); exit( 0 ); } if ( !SetHandleInformation( m_StdoutPipe[PIPE_READ], HANDLE_FLAG_INHERIT, 0 ) ) { printf( "Stdout SetHandleInformation\n" ); exit( 0 ); } string command = QuoteString( path + string("\\") + cmd ); for( int i = 0; i < opts.size(); i++ ) { command += string(" ") + QuoteString( opts[i] ); } char *cmdstr = (char*) malloc( (command.size()+1) * sizeof(char) ); strcpy( cmdstr, command.c_str() ); ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); si.hStdError = m_StdoutPipe[PIPE_WRITE]; si.hStdOutput = m_StdoutPipe[PIPE_WRITE]; si.dwFlags |= STARTF_USESTDHANDLES; ZeroMemory( &pi, sizeof(pi) ); if( !CreateProcess( NULL, // No module name (use command line). TEXT( cmdstr ), // Command line. NULL, // Process handle not inheritable. NULL, // Thread handle not inheritable. TRUE, // Set handle inheritance to FALSE. 0, // No creation flags. NULL, // Use parent's environment block. NULL, // Use parent's starting directory. &si, // Pointer to STARTUPINFO structure. &pi ) // Pointer to PROCESS_INFORMATION structure. ) { printf( "CreateProcess failed (%d).\n", GetLastError() ); return 0; } CloseHandle( m_StdoutPipe[PIPE_WRITE] ); m_StdoutPipe[PIPE_WRITE] = NULL; free( cmdstr ); #else if( pipe( m_StdoutPipe ) < 0 ) { printf( "Error allocating pipe for child output redirect"); return -1; } fcntl( m_StdoutPipe[PIPE_WRITE] , F_SETFL, O_NONBLOCK ); fcntl( m_StdoutPipe[PIPE_READ] , F_SETFL, O_NONBLOCK ); if ( ( childPid = fork() ) == 0 ) { if( dup2( m_StdoutPipe[PIPE_WRITE], STDOUT_FILENO ) == -1 || dup2( m_StdoutPipe[PIPE_WRITE], STDERR_FILENO ) == -1 ) { printf( "Error redirecting child stdout" ); exit( 0 ); } close( m_StdoutPipe[PIPE_READ] ); close( m_StdoutPipe[PIPE_WRITE] ); string command = path + string("/") + cmd; if( cppexecv( command, opts ) < 0 ) { printf( "execv error\n" ); } } else if (childPid < 0) { close( m_StdoutPipe[PIPE_READ] ); close( m_StdoutPipe[PIPE_WRITE] ); printf( "Fork failed (%d).\n", childPid ); return 0; } close( m_StdoutPipe[PIPE_WRITE] ); #endif return 0; }