OpenSchema
From: Alexander Baumgart (Alexander.Baumgart_at_ts.siemens.com)
Date: 02/22/05
- Next message: john: "How set adodb.recordset.filter to a list of long for a long type f"
- Previous message: Stephen Howe: "Re: Is there any (free!) ADO - OLE DB Provider for Lotus Notes?"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 22 Feb 2005 17:55:38 +0100
Hello,
im new to ADO. I try to get all Tables/Index of a Catalog . I wrote 2
function :
int CAcces2SQL_2Dlg::CheckIndex(CString strCatalog, CString strTable,
CString strIndex)
{
_RecordsetPtr m_pRstSchema = NULL;
CString strTemp;
int result = 0;
if (m_pConn)
if (m_pConn->State == adStateOpen)
{
SAFEARRAY FAR* psa = NULL;
SAFEARRAYBOUND rgsabound;
_variant_t var;
_variant_t Array;
rgsabound.lLbound = 0;
rgsabound.cElements = 5;
psa = SafeArrayCreate(VT_VARIANT, 1, &rgsabound);
var.vt = VT_EMPTY;
long ix;
_bstr_t str;
var.vt = VT_BSTR;
str = strCatalog;
var.bstrVal = str;
ix = 0;
SafeArrayPutElement(psa, &ix, &var);
var.vt = VT_EMPTY;
ix = 1;
SafeArrayPutElement(psa, &ix, &var);
var.vt = VT_BSTR;
str = strIndex;
var.bstrVal = str;
ix = 2;
SafeArrayPutElement(psa, &ix, &var);
var.vt = VT_EMPTY;
ix = 3;
SafeArrayPutElement(psa, &ix, &var);
var.vt = VT_BSTR;
str = strTable;
var.bstrVal = str;
ix = 4;
SafeArrayPutElement(psa, &ix, &var);
Array.vt = VT_ARRAY|VT_VARIANT;
Array.parray = psa;
try
{
m_pRstSchema = m_pConn->OpenSchema(adSchemaIndexes,&Array);
}
catch (_com_error &e)
{
CString strErrorLoc = _T("CheckTable");
GenerateError(e, strErrorLoc);
}
// Easy but Unsafe, braucht CursorLocation pConn/pRst = adUseClient
long recCount = 0;
recCount = m_pRstSchema->GetRecordCount();
if (recCount)
{
result = 1;
}
// Clean up objects before exit.
DisConnectRst(m_pRstSchema);
}
return result;
}
int CAcces2SQL_2Dlg::CheckTable(CString strCatalog, CString strTable)
// Setz eine bestehen Connection voraus
{
_RecordsetPtr m_pRstSchema = NULL;
CString strTemp;
int result = 0;
if (m_pConn)
if (m_pConn->State == adStateOpen)
{
SAFEARRAY FAR* psa = NULL;
SAFEARRAYBOUND rgsabound;
_variant_t var;
_variant_t Array;
rgsabound.lLbound = 0;
rgsabound.cElements = 4;
psa = SafeArrayCreate(VT_VARIANT, 1, &rgsabound);
var.vt = VT_EMPTY;
long ix;
_bstr_t str;
var.vt = VT_BSTR;
str = strCatalog;
var.bstrVal = str;
ix = 0;
SafeArrayPutElement(psa, &ix, &var);
var.vt = VT_EMPTY;
ix = 1;
SafeArrayPutElement(psa, &ix, &var);
var.vt = VT_BSTR;
str = strTable;
var.bstrVal = str;
ix = 2;
SafeArrayPutElement(psa, &ix, &var);
var.vt = VT_BSTR;
str = _T("TABLE");
var.bstrVal = str;
ix = 3;
SafeArrayPutElement(psa, &ix, &var);
Array.vt = VT_ARRAY|VT_VARIANT;
Array.parray = psa;
try
{
m_pRstSchema = m_pConn->OpenSchema(adSchemaTables,&Array);
}
catch (_com_error &e)
{
CString strErrorLoc = _T("CheckTable");
GenerateError(e, strErrorLoc);
}
// Easy but Unsafe, braucht CursorLocation pConn/pRst = adUseClient
long recCount = 0;
recCount = m_pRstSchema->GetRecordCount();
if (recCount)
{
result = 1;
// strTemp.Format(_T("Table: %s gefunden \r\n"), (LPCTSTR) strTable);
// m_strOutput+=strTemp;
// UpdateData(FALSE);
}
else
{
// strTemp.Format(_T("Table: %s nicht gefunden \r\n"), (LPCTSTR)
strTable);
// m_strOutput+=strTemp;
// UpdateData(FALSE);
}
/*
while(!(m_pRstSchema->adoEOF))
{
strTemp.Format(_T("Table: %s %d\r\n"), (LPCTSTR) (_bstr_t)
m_pRstSchema->
Fields->GetItem("TABLE_NAME")->Value, recCount);
m_strOutput+=strTemp;
UpdateData(FALSE);
m_pRstSchema->MoveNext();
}
*/
// Clean up objects before exit.
DisConnectRst(m_pRstSchema);
}
return result;
}
void CAcces2SQL_2Dlg::DisConnectRst(_RecordsetPtr pRst)
{
CString strTemp;
// strTemp.Format(_T("RecordSet Status: %s\r\n"), (LPCTSTR)
GetState(m_pRst->State));
// m_strOutput+=strTemp;
// UpdateData(FALSE);
if (pRst)
if (pRst->State == adStateOpen)
{
pRst->Close();
// pRst=NULL;
}
}
CheckTable work, CheckIndex crash with an exception ;( I did a
litte bit tracing and it crashed on the ::Clear of the variant_t ;( Any help
?
Mfg Baumgart
- Next message: john: "How set adodb.recordset.filter to a list of long for a long type f"
- Previous message: Stephen Howe: "Re: Is there any (free!) ADO - OLE DB Provider for Lotus Notes?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|