fastdb_Structures

Structures

FastDB accepts structures as components of records. Fields of the structure can be accessed using the standard dot notation: company.address.city

Structure fields can be indexed and used in an order by specification. Structures can contain other structures as their components; there are no limitations on the nesting level.

The programmer can define methods for structures, which can be used in queries with the same syntax as normal structure components. Such a method should have no arguments except a pointer to the object to which it belongs (the this pointer in C++), and should return an atomic value (of boolean, numeric, string or reference type). Also the method should not change the object instance (immutable method). If the method returns a string, this string should be allocated using the new char operator, because it will be deleted after copying of its value.

So user-defined methods can be used for the creation of virtual components - components which are not stored in the database, but instead are calculated using values of other components. For example, the FastDB dbDateTime type contains only integer timestamp components and such methods as dbDateTime::year(), dbDateTime::month()... So it is possible to specify queries like: "delivery.year = 1999" in an application, where the delivery record field has dbDateTime type. Methods are executed in the context of the application, where they are defined, and are not available to other applications and interactive SQL.

 

FastDB将结构作为记录成员来接收。通过使用标准的点操作符,可以访问结构字段:company.address.city

可以建立结构字段的索引,在特定排序后使用。并且结构可以嵌套其他结构;fastDB对于嵌套的层数没有限制。

 

程序员可以定义结构的方法,在查询的时候可以像调用结构成员一样的语法来调用自定义的结构方法。这样的方法除了带有一个指向方法所属的对象的指针外(如:C++中的this指针),没有其他参数,并且应该返回一个原子类型(布尔类型、数值类型、字符串类型或指针类型)。同时, 这个方法也不能改变对象的实例( 方法的不可改变性)。如果方法返回一个string 类型,接受者必须用new操作数分配空间。因为在复制完它的值之后,返回值将被删除。

所以用户定义的方法可以用来创建一个虚拟成员,这个虚拟成员并不存储在数据库中,而是通过使用其他成员值计算出来的。

 

例如: F a s t D B d b D a t e T i m e 类型仅包含整型的timestamp成员和dbDateTime::year(), dbDateTime::month()...这类方法。所以当记录的字段中含有dbDateTime 类型时,应用程序就可以使用“delivery.year = 1999 这种特定的查询语句。这些方法只能够在定义它们的应用程序的上下文任务中执行,而在其他应用程序和交互式的SQL 中不可使用。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值