Jelajahi Sumber

* Implemented retrieval of basic metadata for TODBCConnection (bug 12975)

git-svn-id: trunk@12558 -
joost 16 tahun lalu
induk
melakukan
c1c62a3ed2

+ 21 - 11
packages/fcl-db/src/sqldb/odbc/odbcconn.pas

@@ -500,12 +500,16 @@ begin
 {$ENDIF}
 
   // prepare statement
-  ODBCCheckResult(
-    SQLPrepare(ODBCCursor.FSTMTHandle, PChar(buf), Length(buf)),
-    SQL_HANDLE_STMT, ODBCCursor.FSTMTHandle, 'Could not prepare statement.'
-  );
-
   ODBCCursor.FQuery:=Buf;
+  if ODBCCursor.FSchemaType=stNoSchema then
+    begin
+      ODBCCheckResult(
+        SQLPrepare(ODBCCursor.FSTMTHandle, PChar(buf), Length(buf)),
+        SQL_HANDLE_STMT, ODBCCursor.FSTMTHandle, 'Could not prepare statement.'
+      );
+    end
+  else
+    ODBCCursor.FStatementType:=stSelect;
 end;
 
 procedure TODBCConnection.UnPrepareStatement(cursor: TSQLCursor);
@@ -553,10 +557,12 @@ begin
     if Assigned(APArams) and (AParams.count > 0) then SetParameters(ODBCCursor, AParams);
 
   // execute the statement
-  ODBCCheckResult(
-    SQLExecute(ODBCCursor.FSTMTHandle),
-    SQL_HANDLE_STMT, ODBCCursor.FSTMTHandle, 'Could not execute statement.'
-  );
+  case ODBCCursor.FSchemaType of
+    stNoSchema  : ODBCCheckResult( SQLExecute(ODBCCursor.FSTMTHandle), SQL_HANDLE_STMT, ODBCCursor.FSTMTHandle, 'Could not execute statement.' );
+    stTables    : ODBCCheckResult( SQLTables (ODBCCursor.FSTMTHandle, nil, 0, nil, 0, nil, 0, nil, 0 ), SQL_HANDLE_STMT, ODBCCursor.FSTMTHandle, 'Could not execute statement.' );
+    stColumns   : ODBCCheckResult( SQLColumns(ODBCCursor.FSTMTHandle, nil, 0, nil, 0, @ODBCCursor.FQuery[1], length(ODBCCursor.FQuery), nil, 0 ), SQL_HANDLE_STMT, ODBCCursor.FSTMTHandle, 'Could not execute statement.' );
+    stProcedures: ODBCCheckResult( SQLProcedures(ODBCCursor.FSTMTHandle, nil, 0, nil, 0, nil, 0 ), SQL_HANDLE_STMT, ODBCCursor.FSTMTHandle, 'Could not execute statement.' );
+  end; {case}
 
   // free parameter buffers
   FreeParamBuffers(ODBCCursor);
@@ -1149,8 +1155,12 @@ end;
 
 function TODBCConnection.GetSchemaInfoSQL(SchemaType: TSchemaType; SchemaObjectName, SchemaObjectPattern: string): string;
 begin
-  Result:=inherited GetSchemaInfoSQL(SchemaType, SchemaObjectName, SchemaObjectPattern);
-  // TODO: implement this
+  if SchemaObjectName<>'' then
+    Result := SchemaObjectName
+  else
+    Result := ' ';
+  if not (SchemaType in [stNoSchema, stTables, stColumns, stProcedures]) then
+    DatabaseError(SMetadataUnavailable);
 end;
 
 { TODBCEnvironment }

+ 2 - 0
packages/fcl-db/src/sqldb/sqldb.pp

@@ -50,6 +50,7 @@ type
     FPrepared      : Boolean;
     FInitFieldDef  : Boolean;
     FStatementType : TStatementType;
+    FSchemaType    : TSchemaType;
   end;
 
 
@@ -942,6 +943,7 @@ begin
     if not assigned(fcursor) then
       FCursor := Db.AllocateCursorHandle;
     FCursor.FStatementType:=StmType;
+    FCursor.FSchemaType := FSchemaType;
     if ServerFiltered then
       Db.PrepareStatement(Fcursor,sqltr,AddFilter(FSQLBuf),FParams)
     else