473,385 Members | 1,429 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,385 developers and data experts.

AntDB’s custom data type: object-oriented features

26 16bit
AntDB extends the relational data model by providing a richer type system, including complex data types and object-oriented, and extends support for the Object-Relational Data Model on the basis of the Relational Query Language to handle a richer type system.

1.Foreword

Many database applications are written in object-oriented programming languages (java, c++), but they need to store data in and fetch data from databases. Because of the type differences between the native type system of object-oriented programming languages and the relational model supported by the database, conversions between the two models are required when fetching or storing data. Extending the database-supported type system alone is not enough to solve this problem completely, because a different language than the programming language must be used to express database access, which makes the programmer's job harder.

In practice, this problem can be solved by integrating object-oriented features with the database system, that is, building an object-relational database system and adding object-oriented features to the relational database system.

AntDB provides a variety of object-oriented features, one of which is custom types, whose usage is described below.

2.Syntax


Figure 1: syntax structure

3.Detailed Description of Functions

You can register a new data type in the database using the CREATE TYPE statement. However, when defining a data type, it is important to note:
  • The creator of a datatype is the owner of the datatype.
  • The schema can be specified at creation time by prefixing the type name with the schema name, otherwise it will be created in the default schema.
  • The name of the new type must not be the same as the existing type name, domain name, or table name in the schema it is in.

As can be seen from the above syntax, a total of five types can be created, namely, combination type, enumeration type, range type, base type, and shell type. The following section focuses on the first four types. Shell type is mainly used as forward references for subsequent definitions when declaring range type and base type, and play the role of type placeholders.

Combination Type

The first form in the syntax description is created as a combination type. A combination type is represented by a list of attribute names and data types. If the data type of the attribute is sortable, you can also specify a sorting rule (collation) for the attribute. A combination type is essentially the same as a table row type, but if you just want to define a type, you can use CREATE TYPE instead of creating a table.

To create a combination type, you must have the USAGE permission on all its attribute types.

Table 1: Syntax Options of Combination Type



Example: *


Figure 2: create a combination type

3.2 Enumeration Type

The second form in the syntax description is created as a enumeration type. An enumeration type is represented by a list of tags with quoted labels, each of which must be no longer than NAMEDATALEN bytes (64 bytes, determined at compile time). It is possible to create enumeration type with zero labels, but such type cannot be used to hold specific values until the labels are added to the enumeration type.

Table 2: Syntax Options of Enumeration Type



Example:


Figure 3 :create a enumeration type

3.3 Range Type

The third form in the syntax description is created as a range type. The range type expresses the range of values of an element type (subtype of range).

Table 3: Syntax Options of Range Type



Example:


Figure 4: create a range type

3.4 Base Type

The forth form in the syntax description is created as a base type. To create a new basic type, you must have superuser privileges (the reason for this restriction is that incorrect type definitions can cause database crashes). The order of the arguments in the above syntax definitions is arbitrary and non-fixed, and many arguments are optional. Usually the function specified in the argument must be defined in C or a lower-level language.

Table 4: Syntax Options of Base Type



Example:


Figure 5 :create a base type

4.Array Type

When a custom type is created, the system automatically creates an associated array type for it. The array type name is prefixed by an underscore to the name of its element type. If the name length exceeds the NAMEDATALEN byte limit it is truncated (if the generated name conflicts with the name of an existing type, the process is repeated until a non-conflicting name is found). This implicitly created array type is variable-length and uses the built-in input and output functions (array_in and array_out). The system also uses this array type when building ARRAY[] on top of user-defined types. This array type changes as the owner or schema of its element type changes, and is deleted when its element type is deleted.

At this point, the reader may have questions, since the system has automatically created the correct array type, why there is still ELEMENT option. This is because ELEMENT works when you create a fixed-length type that happens to be an array of a fixed type and you want to be able to index the data items by subscript. For example, the point type is represented by two floating-point numbers that can be accessed by point[0] and point[1]. This approach is limited to the fact that internally it is an explicit series of fixed-length fields. For historical reasons (which are now unmodifiable), fixed-length arrays start with a subscript of 0, rather than 1 as variable-length arrays do.

5.Compatibility

The above syntax for creating combination types conforms to the SQL standard, the other forms are extended syntax.

6.Conclusion

Custom types provide the most basic object-oriented capabilities. Based on similar ideas, database systems can implement more object-oriented features. More object-oriented features of AntDB will be introduced in the future, so stay tuned.
Jan 12 '23 #1
0 482

Sign in to post your reply or Sign up for a free account.

Similar topics

24
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing the code. Thank you. .. Facundo
21
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
7
by: Luc Tremblay | last post by:
Given the typical following code: void Listener::HandleEvent(const Event& event) { // handling code } In a "clean" fashion, how is it possible to add custom data (to be subsequently...
13
by: dawatson833 | last post by:
I have several stored procedures with parameters that are defined with user defined data types. The time it takes to run the procedures can take 10 - 50 seconds depending on the procedure. If I...
1
by: deko | last post by:
Okay, so I figured out how to pull Outlook Appointments into an Access Table (see below). But the data comes in the wrong Data Type - how do I convert it from Text to Long Integer? For...
21
by: Angel Lopez | last post by:
Sorry if I am too naive, but this is my first post... I have a binary variable (it can contain either a 0 or a 1). Is there any way I can define a data type that uses only 1 bit. So far I have...
13
by: Alan M Dunsmuir | last post by:
I need to specify a new data type, almost entirely a 'clone' of the existing DateTime type, with the following specific difference, and all the consequent differences in properties and methods...
6
by: Gaz | last post by:
Hi guys. I've been lookig for this in the numpy pdf manual, in this group and on google, but i could not get an answer... Is there a way to create a custom data type (eg: Name: string(30), Age:...
12
by: Just D | last post by:
All, It was possible before in Pascal, C++, etc. to define our custom data type or redefine the existing type, like in Turbo Pascal we could assume that shortint is int and use all references to...
1
by: jehugaleahsa | last post by:
Hello: I am experiencing performance related issues when my custom data structures work with value types. I use generics to prevent boxing wherever I can. For instance, I use IEqualityComparer,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.