Gambas Documentation
Application Repository
Code Snippets
Compilation & Installation
Components
Controls pictures
Deprecated components
Developer Documentation
Development Environment Documentation
Documents
About The Best Formula In The World
Architecture details
Benchmarks
Books
By Reference Argument Passing
Compatibility between versions
Creating And Using Libraries
Database Datatype Mapping
Database Request Quoting
Date & time management
Dates and calendars
DBus and Gambas
Differences Between Shell And Exec
Differences From Visual Basic
Distributions & Operating Systems
Drag & Drop
DrawingArea Internal Behaviour
External functions datatype mapping
Frequently Asked Questions
Gambas Farm Server Protocol
Gambas Mailing List Netiquette
Gambas Markdown Syntax
Gambas Naming Conventions
Gambas Object Model
Gambas Scripting
Gambas Server Pages
Gambas Unit Testing
Gambas Wiki Markup Syntax
Getting Started With Gambas
Hall Of Fame
Image Management In Gambas
Including Help Comments in Source Code
Interpreter limits
Introduction
Just In Time Compiler
Just In Time Compiler (old version)
License
Localisation and Internationalization
Mailing Lists & Forums
Naming Conventions
Network Programming
ODBC Component Documentation
PCRE Pattern Syntax
Porting from Gambas 2 to Gambas 3
Previous News
Project Directory Structure
Release Notes
Reporting a problem, a bug or a crash
Rich Text Syntax
Screenshots
Text highlighting definition file syntax
The Program has stopped unexpectedly by raising signal #11
Variable Naming Convention
WebPage Syntax
Web site home page
What Is Gambas?
Window & Form Management
Window Activation & Deactivation
Window Life Cycle
XML APIs
Error Messages
Gambas Playground
How To's
Language Index
Language Overviews
Last Changes
Lexicon
README
Search the wiki
To Do
Topics
Tutorials
Wiki License
Wiki Manual

Database Datatype Mapping

The database component maintains a mapping between each Gambas datatype and each datatype of the underlying database driver.

Of course, this mapping is not bijective. Sometimes a Gambas datatype does not exist in the database system, and, more often, it is the contrary.

Because of that mapping, you must be very careful when you design your database. If you don't want any problem, be sure to always use the database manager provided with Gambas.

Beware with the NULL SQL value!

In Gambas, NULL and the void string are the same thing, but usually it's not in database servers.

Gambas always stores NULL in the database, never a void string, and you must take that into account when writing your SQL requests.

For example, don't do:
SELECT * FROM table WHERE name = '';
But do:
SELECT * FROM table WHERE name IS NULL;

No solution has been found to handle that automatically yet.

MySQL

The mapping for the MySQL database driver is the following:

Gambas datatype MySQL datatype Datatype used by default
Boolean BOOL
TINYINT (length = 1)
BOOL
Integer TINYINT (length > 1)
SMALLINT
MEDIUMINT
INT
YEAR
INT
Long BIGINT BIGINT
Serial INT UNSIGNED NOT NULL AUTO_INCREMENT
BIGINT UNSIGNED NOT NULL AUTO_INCREMENT
BIGINT UNSIGNED NOT NULL AUTO_INCREMENT
Float FLOAT
DOUBLE
DECIMAL
REAL
NUMERIC
DOUBLE
Date TIMESTAMP
DATE
TIME
DATETIME
DATETIME
Blob LONGBLOB
LONGTEXT
BLOB (length >= 16777216)
TEXT (length >= 16777216)
TEXT
String VARCHAR
BLOB (length < 16777216)
TEXT (length < 16777216)
All others.
VARCHAR if length <= 255.
TEXT otherwise.

MySQL makes no difference between a blob or a text field. So Gambas relies on the field length to decide if a field is a text field or a blob.

PostgreSQL

The mapping for the PostgreSQL database driver is the following:

Gambas datatype PostgreSQL datatype Datatype used by default
Boolean BOOL BOOL
Integer INT2
INT4
INT
INT
Long INT8
BIGINT
BIGINT
Serial BIGSERIAL BIGSERIAL
Float NUMERIC
FLOAT4
FLOAT8
FLOAT8
Date ABSTIME
RELTIME
DATE
TIME
TIMESTAMP
DATETIME
TIMESTAMPTZ
TIMESTAMP
Blob BYTEA BYTEA
String CHAR
BPCHAR
VARCHAR
TEXT
NAME
CASH
All others.
VARCHAR
TEXT for unlimited string fields.

SQLite

The mapping for the SQLite database driver is the following:

Gambas datatype SQLite datatype Datatype used by default
Boolean CHAR
TINYINT
INT1
BOOL
BOOL
Integer SMALLINT
INT2
MEDIUMINT
INT
INT4
INT4
Long INT8
BIGINT
BIGINT
Serial INTEGER INTEGER AUTOINCREMENT
Float DECIMAL
NUMERIC
DOUBLE
FLOAT8
REAL
FLOAT
FLOAT4
FLOAT8
Date DATE
TIME
TIMESTAMP
DATETIME
DATETIME
Blob BLOB BLOB
String CHAR()
CLOB
TEXT
VARCHAR
ENUM
SET
YEAR
All others.
VARCHAR
TEXT for unlimited string fields.

ODBC