다음을 통해 공유


EDB Schema Support (Windows Embedded CE 6.0)

1/6/2010

EDB is built on a traditional database engine that supports defining the structure of a database. When you create an EDB database, you define its schema: the number of properties in the database and the data type for each property. You can also define sort orders for the database. By contrast, CEDB does not have the concept of schematization.

Because EDB supports multiple users concurrently accessing the same database, you must ensure that no user has access when schema changes are made. Therefore, it is more efficient to define the schema of an EDB database before the database is used.

Adding and Removing Properties

After designing the schema for an EDB database, add properties to the database. Each property is defined by the CEPROPSPEC (EDB) structure, which is passed to the CeAddDatabaseProps (EDB) and the CeCreateDatabaseWithProps (EDB) functions when adding the property.

Properties are removed from an EDB database by using the CeRemoveDatabaseProps (EDB) function. When a property is added or removed, EDB locks the entire database during the process. Therefore, you cannot add or remove a property if any client has opened the database on any thread.

Note

An EDB database must contain at least one property. All properties except one can be removed.

Naming Properties

EDB requires that each property have a name that is unique for each database. You can specify a user-friendly name for each property, or you can let EDB automatically generate a property name. Name the properties as they are added to the database, using the CEPROPSPEC (EDB) structure with CeAddDatabaseProps. Read the name information by using the CeGetDatabaseProps (EDB) function.

Note

If a naming conflict occurs, EDB returns an ERROR_ALREADY_EXISTS error.

Property ID Mapping

For each property in an EDB database, EDB maps a property ID. If you do not specify a name when adding a property, EDB generates a name based on the property ID. The property ID consists of an application-defined ID in the high word and the data type value in the low word. This ensures that each property name is unique within each database.

Mapping the property ID to each EDB property means that you can have two properties in the same database that have the same application-defined ID, but different data types.

Reading and Writing Property Values

Read property values using the CeReadRecordPropsEx (EDB) function. If you specify an invalid property ID when calling CeReadRecordPropsEx, EDB returns the CEDB_PROPNOTFOUND flag for that property.

Values are written using the CeWriteRecordProps (EDB) function. If you specify an invalid property ID when calling CeWriteRecordProps, the call fails unless the database is currently empty. If the database contains no data, CeWriteRecordProps adds the new property.

Note

The value of an EDB property can be set to NULL. Even if a property is set to NULL, it still uses the storage required for the property. This differs from CEDB, which does not require any storage if there is no value for a property.

Using Sort Orders

Sort orders arrange the data as they are added to the database. You can specify sort orders by using the SORTORDERSPECEX (EDB) structure when calling the CeCreateDatabaseWithProps (EDB) or the CeSetDatabaseInfoEx (EDB) function. When you create a user-defined sort order, EDB automatically adds any property IDs specified in the sort order to the database. Therefore, the client application does not need to define the property IDs when adding a sort order. For more information on property IDs, see Property ID Mapping.

EDB and CEDB Sort Order Compatibility

The following list describes differences between how EDB and CEDB use sort orders:

  • Default sort order
    EDB does not create a default sort order.

  • Unique constraints and NULL values
    If you set the CEDB_SORT_UNIQUE flag in CEDB, the CEDB_SORT_NONNULL flag is implied, and so all records must include all of the sort properties, and none of the properties can be NULL. In EDB, one NULL value is allowed.
    For example, if you have a sort order with two properties, and you have specified CEDB_SORT_UNIQUE, the following table shows the behavior for various values.

    Value EDB behavior CEDB behavior

    A,B

    Valid

    Valid

    A,NULL

    Valid

    Not permitted

    NULL,B

    Valid

    Not permitted

    NULL,NULL

    Valid

    Not permitted

  • Multiple sort orders
    EDB supports up to 16 sort orders, each of which can contain up to 16 properties. CEDB supports only 4 sort orders, each of which can contain up to 3 properties.

  • Properties in sort orders
    EDB allows a property to be used in more than one sort order. This is not possible in CEDB.

  • Property types in sort orders
    CEVT_BLOB and CEVT_LPWSTR data types can be included in a sort order, but the CEVT_STREAM data type cannot.

  • White space truncation
    If you have a sort order with a unique constraint on the CEVT_LPWSTR string data type, EDB truncates any trailing white space in the string value. For example, EDB considers "MyValue" and "MyValue " as the same value. In CEDB, these two strings are considered different.

  • New EDB flags
    EDB supports the following new flags that can be used in the SQLCESORTORDERSPEC::wKeyFlags member:

    • CEDB_SORT_NO_POSITIONAL
      If you do not need positional access on a sort order, specify this flag. By setting this flag, less information is stored in the sort order, saving space. If you use this flag, you must set the pdwIndex parameter to NULL in the call to the CeSeekDatabaseEx (EDB) function.

      Note

      If positional access is disabled for a sort order, only the following seek types are supported with CeSeekDatabaseEx: CEDB_SEEK_CEOID, CEDB_SEEK_BEGINNING, CEDB_SEEK_CURRENT, and CEDB_SEEK_END.

    • CEDB_SORT_PRIMARYKEY
      If you need entity integrity for a sort order, specify this flag. Only one CEDB_SORT PRIMARYKEY constraint can be created per database.

      Note

      A primary key is read-only; a user cannot write a value to this property.

See Also

Reference

CeAddDatabaseProps (EDB)
CeRemoveDatabaseProps (EDB)
CeReadRecordPropsEx (EDB)
CeWriteRecordProps (EDB)
CeCreateDatabaseWithProps (EDB)
CeSetDatabaseInfoEx (EDB)
CeSeekDatabaseEx (EDB)
CEPROPSPEC (EDB)

Other Resources

EDB Database Support