1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
void CDataControl::GetFieldNameCn(const CString& sTableName,CADORecordset* pAdoAccess,const CString& sNameEn, CString& sNameCn)
{
	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; 
	ix   =   0; 
	SafeArrayPutElement(psa,   &ix,   &var); 
 
	ix=   1; 
	SafeArrayPutElement(psa,   &ix,   &var); 
 
	ix   =   2; 
	var.vt   =   VT_BSTR; 
	var.bstrVal   =sTableName.AllocSysString();		//表名  sTableName 
	SafeArrayPutElement(psa,   &ix,   &var); 
 
	var.vt   =   VT_BSTR; 
	ix   =   3; 
	var.bstrVal   =sNameEn.AllocSysString();//字段名
	SafeArrayPutElement(psa,   &ix,   &var); 
 
	Array.vt   =   VT_ARRAY|VT_VARIANT; 
	Array.parray   =   psa;   
 
	pAdoAccess->m_pRecordset   =   pAdoAccess->GetActiveConnection()->OpenSchema(adSchemaColumns,&Array);  
 
	Field *fd = pAdoAccess->m_pRecordset->Fields->GetItem("DESCRIPTION");
	if (fd->GetValue().vt != VT_NULL)
	{
		_bstr_t  column_discription = fd->Value;
		CString sNote;
		sNote.Format(_T("%s"), (LPCTSTR)column_discription);
		sNameCn =  (LPCTSTR)column_discription;
	}
	else
	{
		sNameCn = sNameEn;
	}
}
 
BOOL CDataControl::GetFileNULL(const CString& sTableName,const CString& sFileNameEN,CString& sFileNameCN,CADORecordset* pAdoAccess,BOOL& ISNullSet, int& OrdinalPostion)
{
	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; 
	ix   =   0; 
	SafeArrayPutElement(psa,   &ix,   &var); 
 
	ix=   1; 
	SafeArrayPutElement(psa,   &ix,   &var); 
 
	ix   =   2; 
	var.vt   =   VT_BSTR; 
	var.bstrVal   =sTableName.AllocSysString();		//表名  sTableName 
	SafeArrayPutElement(psa,   &ix,   &var); 
 
	var.vt   =   VT_BSTR; 
	ix   =   3; 
	var.bstrVal   =sFileNameEN.AllocSysString();//字段名
	SafeArrayPutElement(psa,   &ix,   &var); 
 
	Array.vt   =   VT_ARRAY|VT_VARIANT; 
	Array.parray   =   psa;   
 
	pAdoAccess->m_pRecordset   =   pAdoAccess->GetActiveConnection()->OpenSchema(adSchemaColumns,&Array);  
	//IS_NULL = 1 表示字段可以为空   0 表示必填
	ISNullSet = (pAdoAccess->m_pRecordset->Fields->GetItem("IS_NULLABLE")->Value.boolVal == -1)?TRUE:FALSE;//是否允许为空
	_bstr_t  column_name = pAdoAccess->m_pRecordset->Fields->GetItem("COLUMN_NAME")->Value;//字段名
	OrdinalPostion = pAdoAccess->m_pRecordset->Fields->GetItem("ORDINAL_POSITION")->Value;//字段序号
 
	Field *fd = pAdoAccess->m_pRecordset->Fields->GetItem("DESCRIPTION");
	if (fd->GetValue().vt != VT_NULL)
	{
		_bstr_t  column_discription = fd->Value;
		CString sNote;
		sNote.Format(_T("%s"), (LPCTSTR)column_discription);
		sFileNameCN =  (LPCTSTR)column_discription;
	}
	else
	{
		sFileNameCN = sFileNameEN;
	}
 
	//int  NUMERIC_PRECISION = m_pRecordset->Fields->GetItem("NUMERIC_PRECISION")->Value;
	//int  NUMERIC_SCALE = m_pRecordset->Fields->GetItem("NUMERIC_SCALE")->Value;
 
 
	return TRUE;
}
 
BOOL CDataControl::GetFilePkName(const CString& sTableName,std::vector<CString>& sPkName,CADORecordset* pAdoAccess)
{
	SAFEARRAY   FAR*   psa   =   NULL; 
	SAFEARRAYBOUND   rgsabound; 
	_variant_t     var; 
	_variant_t     Array; 
	rgsabound.lLbound   =   0; 
	rgsabound.cElements   =   3; 
	psa   =   SafeArrayCreate(VT_VARIANT,   1,   &rgsabound); 
	var.vt   =   VT_EMPTY; 
	long   ix; 
	ix   =   0; 
	SafeArrayPutElement(psa,   &ix,   &var); 
 
	ix=   1; 
	SafeArrayPutElement(psa,   &ix,   &var); 
 
	ix   =   2; 
	var.vt   =   VT_BSTR; 
	var.bstrVal   =sTableName.AllocSysString();		//表名  sTableName 
	SafeArrayPutElement(psa,   &ix,   &var); 
 
	Array.vt   =   VT_ARRAY|VT_VARIANT; 
	Array.parray   =   psa;   
 
	pAdoAccess->m_pRecordset   =   pAdoAccess->GetActiveConnection()-> OpenSchema(adSchemaPrimaryKeys,&Array);  //adSchemaColumns
 
	while(!pAdoAccess->IsEOF())
	{
		_bstr_t  column_name = pAdoAccess->m_pRecordset->Fields->GetItem("COLUMN_NAME")->Value;
		_bstr_t   column_PK=   pAdoAccess->m_pRecordset-> Fields-> GetItem( "PK_NAME")-> Value; 
 
		sPkName.push_back((LPCTSTR)column_name);
		pAdoAccess->MoveNext();
	}
 
	return TRUE;
}