void SoftProofDialog::slotProfileInfo() { IccProfile profile = d->deviceProfileBox->currentProfile(); if (profile.isNull()) { QMessageBox::critical(this, i18n("Profile Error"), i18n("No profile is selected.")); return; } ICCProfileInfoDlg infoDlg(this, profile.filePath(), profile); infoDlg.exec(); }
void SQLCommandPanel::ExecuteSql() { wxBusyInfo infoDlg(_("Executing sql..."), wxTheApp->GetTopWindow()); clWindowUpdateLocker locker(this); std::set<int> textCols; std::set<int> blobCols; DatabaseLayerPtr m_pDbLayer = m_pDbAdapter->GetDatabaseLayer(m_dbName); if (m_pDbLayer->IsOpen()) { // test for empty command string wxArrayString arrCmdLines = wxStringTokenize( m_scintillaSQL->GetText(), wxT("\n"), wxTOKEN_STRTOK ); int cmdLines = 0; for( size_t i = 0; i < arrCmdLines.GetCount(); i++) { if( ! arrCmdLines[i].Trim(false).StartsWith( wxT("--") ) ) cmdLines++; } // save the history SaveSqlHistory(); if ( cmdLines > 0 ) { try { m_colsMetaData.clear(); if (!m_pDbAdapter->GetUseDb(m_dbName).IsEmpty()) m_pDbLayer->RunQuery(m_pDbAdapter->GetUseDb(m_dbName)); // run query DatabaseResultSet* pResultSet = m_pDbLayer->RunQueryWithResults(m_scintillaSQL->GetText()); // clear variables if(m_gridTable->GetNumberCols()) { m_gridTable->DeleteCols(0, m_gridTable->GetNumberCols()); } if(m_gridTable->GetNumberRows()) { m_gridTable->DeleteRows(0, m_gridTable->GetNumberRows()); } m_gridValues.clear(); if( !pResultSet ) { wxMessageBox( _("Unknown SQL error."), _("DB Error"), wxOK | wxICON_ERROR ); return; } int rows = 0; int cols = pResultSet->GetMetaData()->GetColumnCount(); m_colsMetaData.resize(cols); // create table header m_gridTable->AppendCols(cols); for (int i = 1; i<= pResultSet->GetMetaData()->GetColumnCount(); i++) { m_gridTable->SetColLabelValue(i-1,pResultSet->GetMetaData()->GetColumnName(i)); m_colsMetaData.at(i-1) = ColumnInfo(pResultSet->GetMetaData()->GetColumnType(i), pResultSet->GetMetaData()->GetColumnName(i) ); } m_gridTable->BeginBatch(); // fill table data while (pResultSet->Next()) { wxString value; m_gridTable->AppendRows(); for (int i = 1; i<= pResultSet->GetMetaData()->GetColumnCount(); i++) { switch (pResultSet->GetMetaData()->GetColumnType(i)) { case ResultSetMetaData::COLUMN_INTEGER: if(m_pDbAdapter->GetAdapterType() == IDbAdapter::atSQLITE) { value = pResultSet->GetResultString(i); } else { value = wxString::Format(wxT("%i"),pResultSet->GetResultInt(i)); } break; case ResultSetMetaData::COLUMN_STRING: value = pResultSet->GetResultString(i); break; case ResultSetMetaData::COLUMN_UNKNOWN: value = pResultSet->GetResultString(i); break; case ResultSetMetaData::COLUMN_BLOB: { if(textCols.find(i) != textCols.end()) { // this column should be displayed as TEXT rather than BLOB value = pResultSet->GetResultString(i); } else if(blobCols.find(i) != blobCols.end()) { // this column should be displayed as BLOB wxMemoryBuffer buffer; pResultSet->GetResultBlob(i, buffer); value = wxString::Format(wxT("BLOB (Size:%u)"), buffer.GetDataLen()); } else { // first time wxString strCol = pResultSet->GetResultString(i); if(IsBlobColumn(strCol)) { blobCols.insert(i); wxMemoryBuffer buffer; pResultSet->GetResultBlob(i, buffer); value = wxString::Format(wxT("BLOB (Size:%u)"), buffer.GetDataLen()); } else { textCols.insert(i); value = strCol; } } break; } case ResultSetMetaData::COLUMN_BOOL: value = wxString::Format(wxT("%b"),pResultSet->GetResultBool(i)); break; case ResultSetMetaData::COLUMN_DATE: { wxDateTime dt = pResultSet->GetResultDate(i); if(dt.IsValid()) { value = dt.Format(); } else { value.Clear(); } } break; case ResultSetMetaData::COLUMN_DOUBLE: value = wxString::Format(wxT("%f"),pResultSet->GetResultDouble(i)); break; case ResultSetMetaData::COLUMN_NULL: value = wxT("NULL"); break; default: value = pResultSet->GetResultString(i); break; } m_gridValues[std::make_pair(rows, i-1)] = value; // truncate the string to a reasonable string if(value.Length() > 100) { value = value.Mid(0, 100); value.Append(wxT("...")); } // Convert all whitespace chars into visible ones value.Replace(wxT("\n"), wxT("\\n")); value.Replace(wxT("\r"), wxT("\\r")); value.Replace(wxT("\t"), wxT("\\t")); m_gridTable->SetCellValue(rows, i-1, value); } rows++; } m_gridTable->EndBatch(); m_pDbLayer->CloseResultSet(pResultSet); // show result status m_labelStatus->SetLabel(wxString::Format(_("Result: %i rows"),rows)); Layout(); GetParent()->Layout(); } catch (DatabaseLayerException& e) { // for some reason an exception is thrown even if the error code is 0... if(e.GetErrorCode() != 0) { wxString errorMessage = wxString::Format(_("Error (%d): %s"), e.GetErrorCode(), e.GetErrorMessage().c_str()); wxMessageDialog dlg(this,errorMessage,_("DB Error"),wxOK | wxCENTER | wxICON_ERROR); dlg.ShowModal(); } } catch( ... ) { wxMessageDialog dlg(this,_("Unknown error."),_("DB Error"),wxOK | wxCENTER | wxICON_ERROR); dlg.ShowModal(); } } } else { wxMessageBox(_("Cant connect!")); } }