I have written a small function to to show the content of a geom field as Txt to me for debugging a database on a MSSQL database.
The code seems to be functional most of the time.
For my database I’m debugging: for ~ 300 out of 400 record this code returns the correct spatial polygon information. For ~ 100 records in my database the return value seems to be empty even the MSSQL Server management studio shows geometrical content for these record. This is quite confusing to me.
Question :
a) is there any problem with this code?
b) How could it happen the the query return no polygon for certain records but the MSSQL Server management can draw the information correctly?
function SpatialCheckAsText(FServername, FDatabasename,
FTableName, FFieldName: string; ObjectID: Integer): String;
var
FQuery: TQuery;
FConnection: TConnection;
SQLSTR: string;
begin
FConnection := TConnection.create(nil);
FQuery := TQuery.create(nil);
try
FConnection.LoginPrompt := False;
FQuery.Connection := FConnection;
ConnectToDatabase(FServername, FDatabasename, FConnection);
SQLSTR := 'SELECT ' + FFieldName + '.STAsText() FROM ' + FTableName +
' where RecordIndex=' + IntToStr(ObjectID);
FQuery.SQL.add(SQLSTR);
FQuery.Open;
Result := FQuery.Fields[0].asString +'<end>';
finally
FQuery.Free;
FConnection.Free;
end;
end;
small sample of failing data records with no geom information: