예제 #1
0
void
ReportEdit::modifyNum( const QDateTime & key, int row )
{
	const QString oldText = m_model->index( row, 3 ).data().toString();

	bool ok;

	const QString newText = QInputDialog::getText( this, "Изменить", "Исх. / с/ф", QLineEdit::Normal,
			oldText, &ok );

	if ( ! ok || oldText == newText )
		return;

	PgQuery q;

	q.prepare( QString("UPDATE %1 SET "
				"num = :num "
			"WHERE "
				"%2")
		.arg( _tableName( "log" ) )
		.arg( _dbPg ? "date_trunc( 'second', drec ) = :dt" :
				QString("timestamp = '%1'").arg( key.toString("yyyy-MM-dd hh:mm:ss") ) ) );

	q.bindValue(":num", newText );

	if ( _dbPg )
		q.bindValue(":dt", key );

	if ( q.exec() )
		refresh( key );
	else
		_yell( q );
}
예제 #2
0
void
ReportEdit::deleteRecord( const QDateTime & key, int row )
{
	QDateTime prevKey;

	if ( row > 0 )
		m_model->index( row - 1, 0 ).data().toDateTime();

	PgQuery q;

	q.prepare( QString("DELETE FROM "
			"%1 "
		"WHERE "
			"%2")
		.arg( _tableName( "log" ) )
		.arg( _dbPg ? "date_trunc( 'second', drec ) = :dt" :
				QString("timestamp = '%1'").arg( key.toString("yyyy-MM-dd hh:mm:ss") ) ) );

	if ( _dbPg )
		q.bindValue(":dt", key );

	if ( q.exec() )
		refresh( prevKey );
	else
		_yell( q );
}
예제 #3
0
void
WidgetAddition::updateModelCompleter()
{
	PgQuery q;

	q.prepare( QString("SELECT DISTINCT "
			"trim( %1( city ) ) "
		"FROM "
			"%2 "
		"ORDER BY 1")
			.arg( _dbPg ? "initcap": "" )
			.arg( _tableName( "contact" ) ) );

	if ( q.exec() ) {

		QStringList list;

		while ( q.next() )
			list << q.value( 0 ).toString();

		m_modelCompleter->setStringList( list );

	} else
		_yell( q );
}
예제 #4
0
void
ReportEdit::refresh( const QDateTime & key )
{
	m_model->setQuery( QString("SELECT "
			"%1, "			// datetime is a unique attribute
			"c.who, "
			"l.num_text, "
			"l.num, "
			"CASE WHEN l.zakaz = 0 THEN '' ELSE 'заказное' END, "
			"%2 "
		"FROM "
			"%3 l "
		"INNER JOIN "
			"%4 c ON l.contact_id = c.id "
		"WHERE "
			"%5 "
		"ORDER BY "
			"6 "	// by time
			)
		.arg( _dbPg ? "date_trunc( 'second', l.drec )" : "l.timestamp" )
		.arg( _dbPg ? "\"time\"( l.drec )" : "substr( l.timestamp, 12 )" )
		.arg( _tableName( "log" ) )
		.arg( _tableName( "contact" ) )
		.arg( _dbPg ? QString("date( l.drec ) = '%1'").arg( m_date.toString("yyyy-MM-dd") ) :
				QString("substr( l.timestamp, 1, 10 ) = '%1'").arg( m_date.toString("yyyy-MM-dd") ) ) );

	hideColumn( 0 );	// datetime
	hideColumn( 5 );	// time

	resizeColumnsToContents();

	if ( key.isValid() ) {
		for ( int i = 0; i < m_model->rowCount(); ++i ) {
			if ( m_model->index( i, 0 ).data().toDateTime() == key ) {
				const QModelIndex index = m_model->index( i, 1 );
				setCurrentIndex( index );
				scrollTo( index );
				break;
			}
		}
	}
}
예제 #5
0
void
ReportEdit::toggleZakaz( const QDateTime & key )
{
	PgQuery q;

	q.prepare( QString("UPDATE %1 SET "
			"zakaz = ABS( zakaz - 1 ) "
		"WHERE "
			"%2")
		.arg( _tableName( "log" ) )
		.arg( _dbPg ? "date_trunc( 'second', drec ) = :dt" :
				QString("timestamp = '%1'").arg( key.toString("yyyy-MM-dd hh:mm:ss") ) ) );

	if ( _dbPg )
		q.bindValue(":dt", key );

	if ( q.exec() )
		refresh( key );
	else
		_yell( q );
}
예제 #6
0
HRESULT CSRKeyColumnUsage::Execute(LONG *pcRowsAffected, ULONG cRestrictions, const VARIANT *rgRestrictions)
{
	ATLTRACE2(atlTraceDBProvider, 2, "CSRKeyColumnUsage::Execute()\n");
	////
	int cci_connection_handle = -999;

	WCHAR tableName[128] = {'\0', };

	HRESULT hr = E_FAIL;
	////

	cci_connection_handle = CCUBRIDSession::GetSessionPtr(this)->GetConnection();
	UINT uCodepage = CCUBRIDSession::GetSessionPtr(this)->GetCodepage();
	GetRestrictions(cRestrictions, rgRestrictions, tableName);

	////
	int cci_return_code = -999;
	int cci_request_handle = 0;
	T_CCI_ERROR cci_error_buffer;
	////
#if 1
	CW2A _tableName(tableName, uCodepage);
	cci_return_code = cci_schema_info
		(
		cci_connection_handle, 
		CCI_SCH_PRIMARY_KEY, 
		(tableName[0]? (PSTR) _tableName : NULL), 
		NULL,							// no attribute name is specified.
		CCI_CLASS_NAME_PATTERN_MATCH, 
		&cci_error_buffer
		);
#endif
	if (cci_return_code < 0)
	{
		ATLTRACE2(atlTraceDBProvider, 2, "CSRPrimaryKeys::cci_schema_info() FAILED! \n");
		return RaiseError(E_FAIL, 1, __uuidof(IDBSchemaRowset), CA2W(cci_error_buffer.err_msg, uCodepage));
	}

	cci_request_handle = cci_return_code;

	cci_return_code = cci_cursor(cci_request_handle, 1, CCI_CURSOR_FIRST, &cci_error_buffer);
	if (cci_return_code < 0)
	{
		if (cci_return_code == CCI_ER_NO_MORE_DATA)
		{
			cci_close_req_handle(cci_request_handle);
			return S_OK;
		}
		else
		{
			cci_close_req_handle(cci_request_handle);
			return RaiseError(E_FAIL, 1, __uuidof(IDBSchemaRowset), CA2W(cci_error_buffer.err_msg, uCodepage));
		}
	}

	while (1)
	{
		CKeyColumnUsageRow row;

		hr = FetchData(cci_request_handle, uCodepage, row);
		if (FAILED(hr))
			return hr;

		if (hr == S_OK)
		{
			_ATLTRY
			{
				size_t position = 0;
				for (position = 0; position < m_rgRowData.GetCount() ; position++)
				{
					int result = CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNOREKANATYPE | NORM_IGNOREWIDTH | SORT_STRINGSORT, m_rgRowData[position].GetConstraintName(), -1, row.GetConstraintName(), -1);
					if ( result == CSTR_GREATER_THAN ) 
					{
							break;
					}
					else if (result == CSTR_EQUAL)
					{
						result = CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNOREKANATYPE | NORM_IGNOREWIDTH | SORT_STRINGSORT, m_rgRowData[position].GetTableName(), -1, row.GetTableName(), -1);
						if (result == CSTR_GREATER_THAN)
							break;
						else if (result == CSTR_EQUAL)
						{
							if (m_rgRowData[position].GetOrdinalPosition() >= row.GetOrdinalPosition())
								break;
						}
					}
				}
				m_rgRowData.InsertAt(position, row);
			}
			_ATLCATCHALL()
			{
				cci_close_req_handle(cci_request_handle);
				return E_OUTOFMEMORY;
			}

		}
		cci_return_code = cci_cursor(cci_request_handle, 1, CCI_CURSOR_CURRENT, &cci_error_buffer);
		if (cci_return_code < 0)
		{
			if (cci_return_code == CCI_ER_NO_MORE_DATA)
			{
				cci_close_req_handle(cci_request_handle);
				return S_OK;
			}
			else
			{
				cci_close_req_handle(cci_request_handle);
				return RaiseError(E_FAIL, 1, __uuidof(IDBSchemaRowset), CA2W(cci_error_buffer.err_msg, uCodepage));
			}
		}
	}
예제 #7
0
HRESULT CSRColumns::Execute(LONG * /*pcRowsAffected*/,
				ULONG cRestrictions, const VARIANT *rgRestrictions)
{
	ATLTRACE2(atlTraceDBProvider, 2, "CSRColumns::Execute\n");

	ClearError();

	int hConn = CCUBRIDSession::GetSessionPtr(this)->GetConnection();
	UINT uCodepage = CCUBRIDSession::GetSessionPtr(this)->GetCodepage();
	ULONG ulMaxLen = CCUBRIDSession::GetSessionPtr(this)->GetDataSourcePtr()->PARAM_MAX_STRING_LENGTH;

	WCHAR table_name[1024]; table_name[0] = 0;
	WCHAR column_name[1024]; column_name[0] = 0;
	GetRestrictions(cRestrictions, rgRestrictions, table_name, column_name);

	{
		T_CCI_ERROR err_buf;
		CW2A _tableName(table_name, uCodepage);
		CW2A _columnName(column_name, uCodepage);
		int hReq = cci_schema_info(hConn, CCI_SCH_ATTRIBUTE,
							(table_name[0] ? (PSTR) _tableName : NULL),
							(column_name[0]? (PSTR) _columnName : NULL),
							CCI_CLASS_NAME_PATTERN_MATCH | CCI_ATTR_NAME_PATTERN_MATCH,
							&err_buf);
		if(hReq<0)
		{
			ATLTRACE2("cci_schema_info fail\n");
			return E_FAIL;
		}

		int res = cci_cursor(hReq, 1, CCI_CURSOR_FIRST, &err_buf);
		if(res==CCI_ER_NO_MORE_DATA) goto done;
		if(res<0) goto error;
		while(1)
		{
			CCOLUMNSRow crData;
			HRESULT hr = FetchData(hReq, uCodepage, crData);
			if(FAILED(hr)) goto error;

			//MAX STRING LENGTH 반영
			if (crData.m_ulCharMaxLength != (ULONG)~0 && crData.m_ulCharMaxLength > ulMaxLen)
				crData.m_ulCharMaxLength = ulMaxLen;
			if (crData.m_ulCharMaxLength != (ULONG)~0 && crData.m_ulCharOctetLength > ulMaxLen)
				crData.m_ulCharOctetLength = ulMaxLen;

			_ATLTRY
			{
				// TABLE_NAME 순으로 정렬한다.
				size_t nPos;
				for( nPos=0 ; nPos<m_rgRowData.GetCount() ; nPos++ )
				{
					int res = CompareStringW(LOCALE_USER_DEFAULT, 
							NORM_IGNOREKANATYPE | NORM_IGNOREWIDTH | SORT_STRINGSORT,
							m_rgRowData[nPos].m_szTableName, -1,
							crData.m_szTableName, -1);
					if(res==CSTR_GREATER_THAN) break;
				}
				m_rgRowData.InsertAt(nPos, crData);
			}
			_ATLCATCHALL()
			{
				ATLTRACE2("out of memory\n");
				cci_close_req_handle(hReq);
				return E_OUTOFMEMORY;
			}

			res = cci_cursor(hReq, 1, CCI_CURSOR_CURRENT, &err_buf);
			if(res==CCI_ER_NO_MORE_DATA) goto done;
			if(res<0) goto error;
		}

error:
		ATLTRACE2("fail to fetch data\n");
		cci_close_req_handle(hReq);
		return RaiseError(E_FAIL, 1, __uuidof(IDBSchemaRowset), CA2W(err_buf.err_msg, uCodepage));
done:
		cci_close_req_handle(hReq);
	}

	return S_OK;
}