#
# Testing indexing
#
CREATE TABLE t1
(
matricule INT(4) KEY NOT NULL field_format='Z',
nom       VARCHAR(16) NOT NULL,
prenom    VARCHAR(20) NOT NULL,
sexe      SMALLINT(1) NOT NULL COMMENT 'sexe 1:M 2:F',
aanais    INT(4) NOT NULL,
mmnais    INT(2) NOT NULL,
ddentree  DATE NOT NULL date_format='YYYYMM',
ddnom     DATE NOT NULL date_format='YYYYMM',
brut      INT(5) NOT NULL,
net       DOUBLE(8,2) NOT NULL,
service   INT(2) NOT NULL,
sitmat    CHAR(1) NOT NULL,
formation CHAR(5) NOT NULL,
INDEX NP(nom,prenom)
) ENGINE=CONNECT TABLE_TYPE=FIX FILE_NAME='emp.txt' ENDING=2;
SELECT * FROM t1 LIMIT 10;
matricule	nom	prenom	sexe	aanais	mmnais	ddentree	ddnom	brut	net	service	sitmat	formation
5745	ESCOURCHE	BENEDICTE	2	1935	7	1962-12-01	1994-05-01	18345	14275.50	0	M	TECHN
9692	VICENTE	LAURENCE	2	1941	8	1967-10-01	1989-01-01	16212	13032.80	0	M	ANGL
9146	NICOLAS	ROGER	1	1941	6	1964-07-01	1995-02-01	34173	25098.65	0	M	SANS
2985	TESSEREAU	MARIE HELENE	2	1941	9	1967-01-01	1990-01-01	19323	14933.78	0	V	SANS
3368	MOGADOR	ALAIN	1	1941	1	1961-09-01	1993-11-01	43303	31420.55	0	C	SANS
7394	CHAUSSEE	ERIC DENIS	1	1944	9	1965-11-01	1983-12-01	32002	23583.86	0	M	ANGL
4655	MAILLOT	GEORGES	1	1945	5	1970-09-01	1986-12-01	24700	18541.64	0	C	ANGL
2825	CAMILLE	NADINE	2	1956	9	1994-01-01	1993-01-01	19494	15050.45	0	M	SANS
1460	BRUYERES	JEAN MARC	1	1958	8	1984-08-01	1988-05-01	20902	15980.07	0	M	SANS
4974	LONES	GERARD	1	1959	10	1979-01-01	1994-12-01	16081	12916.70	0	M	SANS
SELECT SUM(brut) from t1;
SUM(brut)
64319029
#
# Testing file mapping
#
ALTER TABLE t1 MAPPED=yes;
SELECT * FROM t1 LIMIT 10;
matricule	nom	prenom	sexe	aanais	mmnais	ddentree	ddnom	brut	net	service	sitmat	formation
5745	ESCOURCHE	BENEDICTE	2	1935	7	1962-12-01	1994-05-01	18345	14275.50	0	M	TECHN
9692	VICENTE	LAURENCE	2	1941	8	1967-10-01	1989-01-01	16212	13032.80	0	M	ANGL
9146	NICOLAS	ROGER	1	1941	6	1964-07-01	1995-02-01	34173	25098.65	0	M	SANS
2985	TESSEREAU	MARIE HELENE	2	1941	9	1967-01-01	1990-01-01	19323	14933.78	0	V	SANS
3368	MOGADOR	ALAIN	1	1941	1	1961-09-01	1993-11-01	43303	31420.55	0	C	SANS
7394	CHAUSSEE	ERIC DENIS	1	1944	9	1965-11-01	1983-12-01	32002	23583.86	0	M	ANGL
4655	MAILLOT	GEORGES	1	1945	5	1970-09-01	1986-12-01	24700	18541.64	0	C	ANGL
2825	CAMILLE	NADINE	2	1956	9	1994-01-01	1993-01-01	19494	15050.45	0	M	SANS
1460	BRUYERES	JEAN MARC	1	1958	8	1984-08-01	1988-05-01	20902	15980.07	0	M	SANS
4974	LONES	GERARD	1	1959	10	1979-01-01	1994-12-01	16081	12916.70	0	M	SANS
SELECT SUM(brut) FROM t1;
SUM(brut)
64319029
#
# Test the indexes (made when creating the table)
#
SELECT * FROM t1 WHERE matricule = '0091';
matricule	nom	prenom	sexe	aanais	mmnais	ddentree	ddnom	brut	net	service	sitmat	formation
91	THIVERNAL	DIDIER JEAN	1	1951	10	1980-05-01	1991-10-01	14715	12024.71	1	M	SANS
SELECT * FROM t1 WHERE nom = 'FOCH';
matricule	nom	prenom	sexe	aanais	mmnais	ddentree	ddnom	brut	net	service	sitmat	formation
1977	FOCH	BERNADETTE	2	1958	3	1992-02-01	1991-02-01	8656	8145.03	1	.	SANS
5707	FOCH	DENIS	1	1977	7	1996-07-01	1995-07-01	7803	7679.36	15	C	COMPT
2552	FOCH	FRANCK	1	1962	12	1986-06-01	1990-11-01	12882	10745.81	13	M	SANS
2634	FOCH	JOCELYNE	2	1953	3	1996-01-01	1995-01-01	12499	10473.09	41	M	INFOR
5765	FOCH	ROBERT	1	1957	1	1981-03-01	1993-03-01	16081	12916.32	52	M	ALLEM
4080	FOCH	SERGE	1	1959	3	1981-03-01	1981-05-01	11131	9658.24	5	M	SANS
SELECT * FROM t1 WHERE nom = 'FOCH' and prenom = 'DENIS';
matricule	nom	prenom	sexe	aanais	mmnais	ddentree	ddnom	brut	net	service	sitmat	formation
5707	FOCH	DENIS	1	1977	7	1996-07-01	1995-07-01	7803	7679.36	15	C	COMPT
#
# Testing UPDATE
#
UPDATE t1 SET aanais = aanais + 16;
UPDATE t1 SET ddentree = adddate(ddentree, interval 16 year);
UPDATE t1 SET ddnom = adddate(ddnom, interval 16 year);
SELECT * FROM t1 WHERE nom = 'FOCH';
matricule	nom	prenom	sexe	aanais	mmnais	ddentree	ddnom	brut	net	service	sitmat	formation
1977	FOCH	BERNADETTE	2	1974	3	2008-02-01	2007-02-01	8656	8145.03	1	.	SANS
5707	FOCH	DENIS	1	1993	7	2012-07-01	2011-07-01	7803	7679.36	15	C	COMPT
2552	FOCH	FRANCK	1	1978	12	2002-06-01	2006-11-01	12882	10745.81	13	M	SANS
2634	FOCH	JOCELYNE	2	1969	3	2012-01-01	2011-01-01	12499	10473.09	41	M	INFOR
5765	FOCH	ROBERT	1	1973	1	1997-03-01	2009-03-01	16081	12916.32	52	M	ALLEM
4080	FOCH	SERGE	1	1975	3	1997-03-01	1997-05-01	11131	9658.24	5	M	SANS
#
# Testing JOIN
#
create table t2
(
sexe  INT(1) KEY,
genre CHAR(8) NOT NULL
) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='sexe.csv' SEP_CHAR=';' ENDING=2;
SELECT * FROM t2;
sexe	genre
0	Inconnu
1	Masculin
2	Feminin
SELECT nom, prenom, genre FROM t1 NATURAL JOIN t2 LIMIT 10;
nom	prenom	genre
ESCOURCHE	BENEDICTE	Feminin
VICENTE	LAURENCE	Feminin
NICOLAS	ROGER	Masculin
TESSEREAU	MARIE HELENE	Feminin
MOGADOR	ALAIN	Masculin
CHAUSSEE	ERIC DENIS	Masculin
MAILLOT	GEORGES	Masculin
CAMILLE	NADINE	Feminin
BRUYERES	JEAN MARC	Masculin
LONES	GERARD	Masculin
#
# Another table
#
CREATE TABLE t3 (
sitmat    CHAR(1) KEY,
situation CHAR(12) NOT NULL
) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='sitmat.csv' SEP_CHAR=';' ENDING=2;
SELECT * FROM t3;
sitmat	situation
.	Inconnu
C	Celibataire
D	Divorce
L	Union libre
M	Marie
S	Separe
V	Veuf
SELECT nom, prenom, genre, situation FROM t1 NATURAL JOIN t2 NATURAL JOIN t3 WHERE nom = 'FOCH';
nom	prenom	genre	situation
FOCH	BERNADETTE	Feminin	Inconnu
FOCH	DENIS	Masculin	Celibataire
FOCH	FRANCK	Masculin	Marie
FOCH	JOCELYNE	Feminin	Marie
FOCH	ROBERT	Masculin	Marie
FOCH	SERGE	Masculin	Marie
#
# Testing DELETE
#
DELETE FROM t1;
DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
