From: http://blog.chinaunix.net/uid-18899774-id-120916.html
For relational databases, arcengine defines several Query Interfaces:
1. Conventional itable and ifeatureclass Interfaces
This is what we use most often. It completes Data Query and update operations in the same table.
// Assume that ifeaturworkspace pfwork has been defined and itableptab = pfwork. OpenTable ("dltb") has been assigned ");
Iqueryfilter pqf = new queryfilterclass ();
Pqf. whereclause = "dlbm like '01 _'";
Icursor pcur = PTAB. Search (pqf, true );
2. iworkspace. executesql
Execute all DDL and dml SQL statements of a relational database. This function bypasses the arcengine storage mechanism when executing SQL statements, and may damage SDE data consistency (mainly when updating SDE system table records). Therefore, you must use this function with caution.
In addition, because this function does not return results after execution, it determines that this function cannot be used to execute query statements.
// Execute the following to update records (sqlserver syntax) to the dljx history file table ).
// Change the creation time of deleted records after
// Assume that iworkspace pwork has been defined and assigned a value.
Pwork. executesql ("Update dljx_h set GDB _
From_date = '2017-1-1 'whereobjectid = 2andgdb _
From_date> '2014-7-13 'and gdb_to_date <'2014-12-31 '");
// Create a table pwork. executesql ("create table ids (ID bigint not null, bindtype varchar (20)") below ))");
3. Use the iquerydef interface to execute various queries
Iquerydef can be used to execute all queries supported by the SQL database engine. If the queried table is a feature class, the latest data of the feature class is returned correctly (even if the feature class enables version management, and the data is not updated to the base table ).
You can also execute some useful queries. Example:
// Query Element Data
// Assume that iworkspace pwork has been defined and assigned a value.
Iquerydef pqdef = pfwork. createquerydef ();
Pqdef. Tables = "dljx ";
Pqdef. whereclause = "jxlx = '97 '";
Icursor pcur = pqdef. Evaluate ();
// Determine whether a table exists (if the table is not registered as a geometrytable, it may not be obtained through iworkspace2.nameexists)
Pqdef. subfields = "ID ";
Pqdef. Tables = "sysobjects ";
Pqdef. whereclause = "id = object_id (N 'id') and objectproperty (ID, N 'isusertable') = 1"; icursor pcur = pqdef. Evaluate ();
Irow prow = pcur. nextrow ();
If (prow! = NULL) {bexist = true ;}
// Aggregate Query
// Note: As arcengine only splits subfields content with commas (,), the Field names must be pushed back in sequence if commas (,) are included, field alias definition is not supported.
Pqdef. subfields = "count (*), sum (tdzmj), sum (kzzmj), left (zldwdm, 6 )";
Pqdef. Tables = "dltb group by left (zldwdm, 6)"; icursor pcur = pqdef. Evaluate ();
For the icursor returned above, although the actual record has only four fields, but icursor. fields has five elements: Count (*), sum (tdzmj), sum (kzzmj), left (zldwdm, 6) therefore, to obtain the value of the fourth field, you need to: int i133 = pcur. findfield ("Left (zldwdm ");
Irow prow = pcur. nextrow ();
String SDM = prow. get_value (IDM). tostring ();
// Multi-table join query
Pqdef. Tables = "dltb a left join xzq B on
A. zldwdm = B. xzqdm"
Icursor pcur = pqdef. Evaluate ();
4. Use the arcengine statistical class (implementing the idatastatistics Interface)
// Assume that ifeaturworkspace pfwork has been defined and assigned a value.
Itable PTAB = pfwork. OpenTable ("dltb ");
Icursor pcur = pdltbtable. Search (null, false );
I d a t a s t a t I s t I c S P d a T A S T A T = N E W
Datastatisticsclass ();
Pdatastat. Field = "mj ";
Pdatastat. cursor = pcur;
Istatisticsresults pres = datastatistics.
Statistics;
// You can call interface-related methods, such as Count: Pres. Sum
In practical applications, 1st and 3rd methods are used most often, which can basically meet the needs of most data queries.
4th methods are used completely. However, if the application needs to adapt to multiple database types, 3rd methods are more convenient, but the performance is certainly not as high as 4th methods, in addition, you cannot perform multi-table join queries in the 4th methods. In my opinion, except for obtaining the unique value, 3rd methods can be used in other cases. If the query syntax format is different for different database types, multiple versions can be implemented by dynamically determining the database type.
2nd methods, which are generally not recommended. The reason is that there is no return value, which is mainly used for database maintenance or record update operations. The operations performed outside the SDE system may damage the integrity and consistency of the SDE data structure. However, it cannot be said that this method is useless. As a supplement to other methods, it can be used to create custom tables outside the storage process, view, and SDE system. In addition, if you are familiar with SDE system tables, you can perform some underlying maintenance, such as modifying the timestamp of History Table records and modifying locks.