diff --git a/dist/dbtypes.html b/dist/dbtypes.html index ee2199b..92ccbdc 100644 --- a/dist/dbtypes.html +++ b/dist/dbtypes.html @@ -1,249 +1,249 @@ - - -SchemaSpy Database Types - - - - -

SchemaSpy Database Types

- -One goal of SchemaSpy is to support a wide range of JDBC-complaint databases. -It uses the concept of "database types", as specified by .properties files, to -achieve that goal. -Out of the box SchemaSpy supports a multitude of databases. -If your database isn't currently supported or needs to be customized then continue reading. - -

For SchemaSpy to support your database it must: -

    -
  1. Have JDBC drivers available
  2. -
  3. The JDBC drivers must provide JDBC metadata
  4. -
- -The vast majority of relational databases have JDBC drivers that provide appropriate metadata. - -

Database Type .properties Files

-

The -t command-line parameter specified which type of database you're dealing with. -For example: -t mysql says to use the MySQL-specific database type file -named mysql.properties. -This file, by default, lives in the SchemaSpy jar file, but if you specify a path to the -file then it can also reside on your file system so you can easily modify / experiment -with the file's settings. - -

Let's start with a simple (and typical) database type file called mysql.properties. -The basic file looks like this: -

-  description=MySQL
-
-  driver=com.mysql.jdbc.Driver
-
-  connectionSpec=jdbc:mysql://<host>/<db>
-  host=hostname[:port] host where database resides with optional port
-  db=database name
-
-See the entire MySQL configuration file -here. - -

Basic entries

-
description
-
- Simple description of the type of database. -
-
driver
-
- The full name of the driver class that provides the required JDBC services. - This class name is provided by the database driver vendor. - Use the -dp (driver path) command-line option to point to the - .jar or .zip that contains this class. -
-
connectionSpec
-
- The format of the connection spec is defined by the database driver vendor. - It usually has a format similar to the one used for MySQL: jdbc:mysql://<host>/<db> -
The names surrounded by < and > are required by the driver vendor - and will become required parameters on the SchemaSpy command line. - Those command line values will be substituted into the connection spec - before it is used to connect to the database. -
-
host and db
-
- These will vary for each type of database and provide documentation for the - names surrounded by < and > in connectionSpec. - For example, if you forget to specify -host on the command line then you will - get an error message that includes the text: -

hostname[:port] host where database resides with optional port -

The idea is to have meaningful error messages / descriptions of these - database-specific parameters. -

- -

Custom SQL

-The remaining entries in the .properties file are not required for most databases. -They're typically used to provide functionality that either isn't provided by the -JDBC metadata services or when those services are in some way inappropriate -(performance, incorrect results, etc.). - -

For these SQL-based entries you can use optional "named parameters" in the SQL. -These named parameters are -:schema, :owner, :table and :view. -They will be substituted with appropriate values at runtime. -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameRequired ColumnsOptional ColumnsReturnsScope of query
selectTablesSqltable_nametable_catalog, table_schema, table_comment, table_rowsBasic information about all tables in a specific schema.Database
selectViewsSqlview_name, view_definitionview_catalog, view_schema, view_commentBasic information about all views in a specific schema.Database
selectIndexesSqlindex_name, column_name, type, asc_or_desc (docs) Information about indexes in a specific table.Single table
selectRowCountSqlrow_count Number of rows in a specific table.Single table
selectTableCommentsSqltable_name, comments Comments associated with tables and (optionally) views.
- Useful if the database driver doesn't return this info or if it's persisted elsewhere.
Database
selectViewCommentsSqlview_name, comments Comments associated with views.
- Optionally defined if selectTableCommentsSql doesn't return view comments.
Database
selectColumnCommentsSqltable_name, column_name, comments Comments associated with table columns and (optionally) view columns.
- Useful if the database driver doesn't return this info or if it's persisted elsewhere.
Database
selectViewColumnCommentsSqlview_name, column_name, comments Comments associated with view columns.
- Optionally defined if selectColumnCommentsSql doesn't return view column comments.
Database
selectCheckConstraintsSqlconstraint_name, table_name, text Check constraint details of all check constraints, where 'text' is usually - the SQL used to create the constraint. - These details will be displayed on the table detail pages. - Database
selectViewSqlview_definition Details of a specific view, usually the SQL used to create the view. - These details will be displayed on the view detail pages. - Single view
selectColumnTypesSqltable_name, column_name, column_typeshort_column_typeDetails of unusual column types such as ENUMs. - The short version is used within ER diagrams to help make them more readable. - Database
selectTableIdsSqltable_id, table_name Unique ID for each table. - This is useful for databases (such as DB2) that may give error messages with just - table IDs instead of names.Database
selectIndexIdsSqlindex_id, index_name, table_name Unique ID for each table index. - This is useful for databases (such as DB2) that may give error messages with just - index IDs instead of names.Database
- -

Reusing Configurations

-For those instances where you have two almost identical configurations you can -use the extends directive, specifying another .properties file to be "extended." -Interaction with DB2 through its "type 4 network driver", for example, is almost identical -to the the DB2 "app driver". -db2net.properties therefore has a line that reads -extends=db2 and only includes those configuration options that -deviate from db2.properties. -

-Another related directive is include. -It "includes" a key=value pair from another .properties file. -The format is include.x=dbtype::key where -

-The include directive is useful for reusing complex portions of configuration -files (such as the SQL customization settings shown above) while extending other files. -See -mssql05-jtds.properties as an example. - -

Single-Threaded Drivers

-There's one remaining database configuration entry named dbThreads. -It is used for database drivers whose metadata queries aren't thread safe. -If your driver returns failures like "stream already closed" then you'll need -to specify either dbThreads=1 in your .properties or "-dbThreads 1" -on the command line. - - + + +SchemaSpy Database Types + + + + +

SchemaSpy Database Types

+ +One goal of SchemaSpy is to support a wide range of JDBC-complaint databases. +It uses the concept of "database types", as specified by .properties files, to +achieve that goal. +Out of the box SchemaSpy supports a multitude of databases. +If your database isn't currently supported or needs to be customized then continue reading. + +

For SchemaSpy to support your database it must: +

    +
  1. Have JDBC drivers available
  2. +
  3. The JDBC drivers must provide JDBC metadata
  4. +
+ +The vast majority of relational databases have JDBC drivers that provide appropriate metadata. + +

Database Type .properties Files

+

The -t command-line parameter specified which type of database you're dealing with. +For example: -t mysql says to use the MySQL-specific database type file +named mysql.properties. +This file, by default, lives in the SchemaSpy jar file, but if you specify a path to the +file then it can also reside on your file system so you can easily modify / experiment +with the file's settings. + +

Let's start with a simple (and typical) database type file called mysql.properties. +The basic file looks like this: +

+  description=MySQL
+
+  driver=com.mysql.jdbc.Driver
+
+  connectionSpec=jdbc:mysql://<host>/<db>
+  host=hostname[:port] host where database resides with optional port
+  db=database name
+
+See the entire MySQL configuration file +here. + +

Basic entries

+
description
+
+ Simple description of the type of database. +
+
driver
+
+ The full name of the driver class that provides the required JDBC services. + This class name is provided by the database driver vendor. + Use the -dp (driver path) command-line option to point to the + .jar or .zip that contains this class. +
+
connectionSpec
+
+ The format of the connection spec is defined by the database driver vendor. + It usually has a format similar to the one used for MySQL: jdbc:mysql://<host>/<db> +
The names surrounded by < and > are required by the driver vendor + and will become required parameters on the SchemaSpy command line. + Those command line values will be substituted into the connection spec + before it is used to connect to the database. +
+
host and db
+
+ These will vary for each type of database and provide documentation for the + names surrounded by < and > in connectionSpec. + For example, if you forget to specify -host on the command line then you will + get an error message that includes the text: +

hostname[:port] host where database resides with optional port +

The idea is to have meaningful error messages / descriptions of these + database-specific parameters. +

+ +

Custom SQL

+The remaining entries in the .properties file are not required for most databases. +They're typically used to provide functionality that either isn't provided by the +JDBC metadata services or when those services are in some way inappropriate +(performance, incorrect results, etc.). + +

For these SQL-based entries you can use optional "named parameters" in the SQL. +These named parameters are +:schema, :owner, :table and :view. +They will be substituted with appropriate values at runtime. +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameRequired ColumnsOptional ColumnsReturnsScope of query
selectTablesSqltable_nametable_catalog, table_schema, table_comment, table_rowsBasic information about all tables in a specific schema.Database
selectViewsSqlview_name, view_definitionview_catalog, view_schema, view_commentBasic information about all views in a specific schema.Database
selectIndexesSqlindex_name, column_name, type, asc_or_desc (docs) Information about indexes in a specific table.Single table
selectRowCountSqlrow_count Number of rows in a specific table.Single table
selectTableCommentsSqltable_name, comments Comments associated with tables and (optionally) views.
+ Useful if the database driver doesn't return this info or if it's persisted elsewhere.
Database
selectViewCommentsSqlview_name, comments Comments associated with views.
+ Optionally defined if selectTableCommentsSql doesn't return view comments.
Database
selectColumnCommentsSqltable_name, column_name, comments Comments associated with table columns and (optionally) view columns.
+ Useful if the database driver doesn't return this info or if it's persisted elsewhere.
Database
selectViewColumnCommentsSqlview_name, column_name, comments Comments associated with view columns.
+ Optionally defined if selectColumnCommentsSql doesn't return view column comments.
Database
selectCheckConstraintsSqlconstraint_name, table_name, text Check constraint details of all check constraints, where 'text' is usually + the SQL used to create the constraint. + These details will be displayed on the table detail pages. + Database
selectViewSqlview_definition Details of a specific view, usually the SQL used to create the view. + These details will be displayed on the view detail pages. + Single view
selectColumnTypesSqltable_name, column_name, column_typeshort_column_typeDetails of unusual column types such as ENUMs. + The short version is used within ER diagrams to help make them more readable. + Database
selectTableIdsSqltable_id, table_name Unique ID for each table. + This is useful for databases (such as DB2) that may give error messages with just + table IDs instead of names.Database
selectIndexIdsSqlindex_id, index_name, table_name Unique ID for each table index. + This is useful for databases (such as DB2) that may give error messages with just + index IDs instead of names.Database
+ +

Reusing Configurations

+For those instances where you have two almost identical configurations you can +use the extends directive, specifying another .properties file to be "extended." +Interaction with DB2 through its "type 4 network driver", for example, is almost identical +to the the DB2 "app driver". +db2net.properties therefore has a line that reads +extends=db2 and only includes those configuration options that +deviate from db2.properties. +

+Another related directive is include. +It "includes" a key=value pair from another .properties file. +The format is include.x=dbtype::key where +

+The include directive is useful for reusing complex portions of configuration +files (such as the SQL customization settings shown above) while extending other files. +See +mssql05-jtds.properties as an example. + +

Single-Threaded Drivers

+There's one remaining database configuration entry named dbThreads. +It is used for database drivers whose metadata queries aren't thread safe. +If your driver returns failures like "stream already closed" then you'll need +to specify either dbThreads=1 in your .properties or "-dbThreads 1" +on the command line. + + \ No newline at end of file diff --git a/library.ddl b/library.ddl index 07f06fb..e214a3e 100644 --- a/library.ddl +++ b/library.ddl @@ -1,297 +1,297 @@ -drop database if exists library; -create database library; -commit; -connect library; - -create table ADDRESS ( - addressId integer auto_increment, - address1 varchar(50) not null comment 'Address line 1', - address2 varchar(50) comment 'Address line 2 (optional)', - city varchar(30) not null, - state char(2) not null, - zip varchar(10) not null comment "Dash req'd for zip+4", - primary key(AddressId) -) engine=InnoDB COMMENT='Address details'; - -create table PUBLISHER ( - publisherId integer auto_increment, - name varchar(64) not null, - address integer, - phone varchar(16), - primary key(publisherId), - foreign key(address) references ADDRESS(addressId), - index(name) -) engine=InnoDB; - -create table BOOK ( - isbn bigint, - title varchar(128) not null, - publisherId integer auto_increment not null, - primary key (isbn), - foreign key (publisherId) references PUBLISHER(publisherId), - index (title) -) engine=InnoDB COMMENT='Book details'; - -create table author ( - authorId integer auto_increment, - firstName varchar(32) not null, - middleName varchar(32) null, - lastName varchar(32) not null, - primary key (authorId), - index (lastName) -) engine=InnoDB; - -create table book_author ( - isbn bigint, - authorId integer comment 'FK intentionally omitted to show an implied relationship', - primary key (isbn, authorId), - foreign key (isbn) references BOOK(isbn) -) engine=InnoDB; --- foreign key (authorId) references author(authorId) - -create table LIBRARY_BRANCH ( - branchId integer auto_increment auto_increment, - name varchar(64) not null, - address integer not null, - primary key(BranchId), - foreign key(Address) references ADDRESS(AddressId) -) engine=InnoDB; - -create table BOOK_LOCATION ( - isbn bigint, - branchId integer not null, - numCopies integer not null, - primary key(isbn, branchId), - foreign key(isbn) references BOOK(isbn), - foreign key(branchId) references LIBRARY_BRANCH(branchId) -) engine=InnoDB; - -create table BORROWER ( - cardNo integer auto_increment, - firstName varchar(32) not null, - middleName varchar(32) null, - lastName varchar(32) not null, - address integer, - phone varchar(16), - primary key(cardNo), - foreign key(Address) references ADDRESS(AddressId), - index(lastName, firstName) -) engine=InnoDB; - -create table borrowed_book ( - isbn bigint, - branchId integer not null, - cardNo integer not null, - borrowDate date not null, - dueDate date not null, - primary key (isbn, branchId, cardNo), - foreign key (isbn) references BOOK(isbn), - foreign key (branchId) references LIBRARY_BRANCH(branchId), - foreign key (cardNo) references BORROWER(cardNo), - index (DueDate) -) engine=InnoDB; - -insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920'); -insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920'); -insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920'); -insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920'); -insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920'); -insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920'); -insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920'); -insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920'); -insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920'); -insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); -insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); -insert into publisher values(null, 'AW', 3, '123'); -insert into publisher values(null, 'AW', 3, '123'); -insert into publisher values(null, 'AW', 3, '123'); -insert into publisher values(null, 'AW', 3, '123'); -insert into publisher values(null, 'AW', 3, '123'); -insert into book values(100, 100, 1); -insert into book values(101, 100, 1); -insert into book values(102, 100, 1); -insert into book values(103, 100, 1); -insert into book values(104, 100, 1); -insert into book values(105, 100, 1); -insert into book values(106, 100, 1); -insert into book values(107, 100, 1); -insert into book values(108, 100, 1); -insert into book values(109, 100, 1); -insert into book values(110, 100, 1); -insert into book values(111, 100, 1); -insert into book values(112, 100, 1); -insert into book values(113, 100, 1); -insert into book values(114, 100, 1); -insert into book values(115, 100, 1); -insert into book values(116, 100, 1); -insert into book values(117, 100, 1); -insert into book values(118, 100, 1); -insert into book values(119, 100, 1); -insert into book values(120, 100, 1); -insert into book values(121, 100, 1); -insert into book values(122, 100, 1); -insert into book values(123, 100, 1); -insert into book values(124, 100, 1); -insert into book values(125, 100, 1); -insert into book values(126, 100, 1); -insert into book values(127, 100, 1); -insert into book values(128, 100, 1); -insert into book values(129, 100, 1); -insert into book values(130, 100, 1); -insert into book values(131, 100, 1); -insert into book values(132, 100, 1); -insert into book values(133, 100, 1); -insert into book values(134, 100, 1); -insert into book values(135, 100, 1); -insert into book values(136, 100, 1); -insert into book values(137, 100, 1); -insert into book values(138, 100, 1); -insert into book values(139, 100, 1); -insert into book values(140, 100, 1); -insert into book values(141, 100, 1); -insert into book values(142, 100, 1); -insert into book values(143, 100, 1); -insert into book values(144, 100, 1); -insert into book values(145, 100, 1); -insert into book values(146, 100, 1); -insert into book values(147, 100, 1); -insert into book values(148, 100, 1); -insert into book values(149, 100, 1); -insert into book values(150, 100, 1); -insert into book values(151, 100, 1); -insert into book values(152, 100, 1); -insert into book values(153, 100, 1); -insert into book values(154, 100, 1); -insert into book values(155, 100, 1); -insert into book values(156, 100, 1); -insert into book values(157, 100, 1); -insert into book values(158, 100, 1); -insert into book values(159, 100, 1); -insert into book values(160, 100, 1); -insert into book values(161, 100, 1); -insert into book values(162, 100, 1); -insert into book values(163, 100, 1); -insert into book values(164, 100, 1); -insert into book values(165, 100, 1); -insert into book values(166, 100, 1); -insert into book values(167, 100, 1); -insert into book values(168, 100, 1); -insert into book values(169, 100, 1); -insert into book values(170, 100, 1); -insert into book values(171, 100, 1); -insert into book values(172, 100, 1); -insert into book values(173, 100, 1); -insert into book values(174, 100, 1); -insert into book values(175, 100, 1); -insert into book values(176, 100, 1); -insert into book values(177, 100, 1); -insert into book values(178, 100, 1); -insert into book values(179, 100, 1); -insert into library_branch values(null, 'Central', 5); -insert into book_location values(100, 1, 1); -insert into book_location values(101, 1, 1); -insert into book_location values(102, 1, 1); -insert into book_location values(103, 1, 1); -insert into book_location values(104, 1, 1); -insert into book_location values(105, 1, 1); -insert into book_location values(106, 1, 1); -insert into book_location values(107, 1, 1); -insert into book_location values(108, 1, 1); -insert into book_location values(109, 1, 1); -insert into book_location values(110, 1, 1); -insert into book_location values(111, 1, 1); -insert into book_location values(112, 1, 1); -insert into book_location values(113, 1, 1); -insert into book_location values(114, 1, 1); -insert into book_location values(115, 1, 1); -insert into book_location values(116, 1, 1); -insert into book_location values(117, 1, 1); -insert into book_location values(118, 1, 1); -insert into book_location values(119, 1, 1); -insert into book_location values(120, 1, 1); -insert into book_location values(121, 1, 1); -insert into book_location values(122, 1, 1); -insert into book_location values(123, 1, 1); -insert into book_location values(124, 1, 1); -insert into book_location values(125, 1, 1); -insert into book_location values(126, 1, 1); -insert into book_location values(127, 1, 1); -insert into book_location values(128, 1, 1); -insert into book_location values(129, 1, 1); -insert into book_location values(130, 1, 1); -insert into book_location values(131, 1, 1); -insert into book_location values(132, 1, 1); -insert into book_location values(133, 1, 1); -insert into book_location values(134, 1, 1); -insert into book_location values(135, 1, 1); -insert into book_location values(136, 1, 1); -insert into book_location values(137, 1, 1); -insert into book_location values(138, 1, 1); -insert into book_location values(139, 1, 1); -insert into book_location values(140, 1, 1); -insert into book_location values(141, 1, 1); -insert into book_location values(142, 1, 1); -insert into book_location values(143, 1, 1); -insert into book_location values(144, 1, 1); -insert into book_location values(145, 1, 1); -insert into book_location values(146, 1, 1); -insert into book_location values(147, 1, 1); -insert into book_location values(148, 1, 1); -insert into book_location values(149, 1, 1); -insert into borrowed_book values(100, 1, 1, '1999-10-31', '1999-10-31'); -insert into borrowed_book values(101, 1, 2, '1999-10-31', '1999-10-31'); -insert into library_branch values(null, 'Central', 8); -insert into library_branch values(null, 'Central', 7); -insert into library_branch values(null, 'Central', 5); -insert into author values(null, "author1", null, "author1"); -insert into author values(null, "author2", null, "author2"); -insert into author values(null, "author3", null, "author3"); -insert into author values(null, "author4", null, "author4"); -insert into author values(null, "author5", null, "author5"); -insert into author values(null, "author6", null, "author6"); -insert into author values(null, "author7", null, "author7"); -insert into author values(null, "author8", null, "author8"); -insert into author values(null, "author9", null, "author9"); -insert into book_author values(101, 1); -insert into book_author values(101, 2); -insert into book_author values(102, 3); -insert into book_author values(103, 4); -insert into book_author values(104, 5); -insert into book_author values(105, 6); -insert into book_author values(106, 7); -insert into book_author values(107, 8); - - --- select branchname, count(*) from library_branch group by branchname, branchid; - --- insert into borrower values(null, 'akshai', 9, '456'); - +drop database if exists library; +create database library; +commit; +connect library; + +create table ADDRESS ( + addressId integer auto_increment, + address1 varchar(50) not null comment 'Address line 1', + address2 varchar(50) comment 'Address line 2 (optional)', + city varchar(30) not null, + state char(2) not null, + zip varchar(10) not null comment "Dash req'd for zip+4", + primary key(AddressId) +) engine=InnoDB COMMENT='Address details'; + +create table PUBLISHER ( + publisherId integer auto_increment, + name varchar(64) not null, + address integer, + phone varchar(16), + primary key(publisherId), + foreign key(address) references ADDRESS(addressId), + index(name) +) engine=InnoDB; + +create table BOOK ( + isbn bigint, + title varchar(128) not null, + publisherId integer auto_increment not null, + primary key (isbn), + foreign key (publisherId) references PUBLISHER(publisherId), + index (title) +) engine=InnoDB COMMENT='Book details'; + +create table author ( + authorId integer auto_increment, + firstName varchar(32) not null, + middleName varchar(32) null, + lastName varchar(32) not null, + primary key (authorId), + index (lastName) +) engine=InnoDB; + +create table book_author ( + isbn bigint, + authorId integer comment 'FK intentionally omitted to show an implied relationship', + primary key (isbn, authorId), + foreign key (isbn) references BOOK(isbn) +) engine=InnoDB; +-- foreign key (authorId) references author(authorId) + +create table LIBRARY_BRANCH ( + branchId integer auto_increment auto_increment, + name varchar(64) not null, + address integer not null, + primary key(BranchId), + foreign key(Address) references ADDRESS(AddressId) +) engine=InnoDB; + +create table BOOK_LOCATION ( + isbn bigint, + branchId integer not null, + numCopies integer not null, + primary key(isbn, branchId), + foreign key(isbn) references BOOK(isbn), + foreign key(branchId) references LIBRARY_BRANCH(branchId) +) engine=InnoDB; + +create table BORROWER ( + cardNo integer auto_increment, + firstName varchar(32) not null, + middleName varchar(32) null, + lastName varchar(32) not null, + address integer, + phone varchar(16), + primary key(cardNo), + foreign key(Address) references ADDRESS(AddressId), + index(lastName, firstName) +) engine=InnoDB; + +create table borrowed_book ( + isbn bigint, + branchId integer not null, + cardNo integer not null, + borrowDate date not null, + dueDate date not null, + primary key (isbn, branchId, cardNo), + foreign key (isbn) references BOOK(isbn), + foreign key (branchId) references LIBRARY_BRANCH(branchId), + foreign key (cardNo) references BORROWER(cardNo), + index (DueDate) +) engine=InnoDB; + +insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920'); +insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920'); +insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920'); +insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920'); +insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920'); +insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920'); +insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920'); +insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920'); +insert into address values(null, 'Road Road', '', 'Colorado Springs', 'CO', '80920'); +insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 2, '123'); +insert into borrower values(null, 'firstName', '', 'lastName', 1, '123'); +insert into publisher values(null, 'AW', 3, '123'); +insert into publisher values(null, 'AW', 3, '123'); +insert into publisher values(null, 'AW', 3, '123'); +insert into publisher values(null, 'AW', 3, '123'); +insert into publisher values(null, 'AW', 3, '123'); +insert into book values(100, 100, 1); +insert into book values(101, 100, 1); +insert into book values(102, 100, 1); +insert into book values(103, 100, 1); +insert into book values(104, 100, 1); +insert into book values(105, 100, 1); +insert into book values(106, 100, 1); +insert into book values(107, 100, 1); +insert into book values(108, 100, 1); +insert into book values(109, 100, 1); +insert into book values(110, 100, 1); +insert into book values(111, 100, 1); +insert into book values(112, 100, 1); +insert into book values(113, 100, 1); +insert into book values(114, 100, 1); +insert into book values(115, 100, 1); +insert into book values(116, 100, 1); +insert into book values(117, 100, 1); +insert into book values(118, 100, 1); +insert into book values(119, 100, 1); +insert into book values(120, 100, 1); +insert into book values(121, 100, 1); +insert into book values(122, 100, 1); +insert into book values(123, 100, 1); +insert into book values(124, 100, 1); +insert into book values(125, 100, 1); +insert into book values(126, 100, 1); +insert into book values(127, 100, 1); +insert into book values(128, 100, 1); +insert into book values(129, 100, 1); +insert into book values(130, 100, 1); +insert into book values(131, 100, 1); +insert into book values(132, 100, 1); +insert into book values(133, 100, 1); +insert into book values(134, 100, 1); +insert into book values(135, 100, 1); +insert into book values(136, 100, 1); +insert into book values(137, 100, 1); +insert into book values(138, 100, 1); +insert into book values(139, 100, 1); +insert into book values(140, 100, 1); +insert into book values(141, 100, 1); +insert into book values(142, 100, 1); +insert into book values(143, 100, 1); +insert into book values(144, 100, 1); +insert into book values(145, 100, 1); +insert into book values(146, 100, 1); +insert into book values(147, 100, 1); +insert into book values(148, 100, 1); +insert into book values(149, 100, 1); +insert into book values(150, 100, 1); +insert into book values(151, 100, 1); +insert into book values(152, 100, 1); +insert into book values(153, 100, 1); +insert into book values(154, 100, 1); +insert into book values(155, 100, 1); +insert into book values(156, 100, 1); +insert into book values(157, 100, 1); +insert into book values(158, 100, 1); +insert into book values(159, 100, 1); +insert into book values(160, 100, 1); +insert into book values(161, 100, 1); +insert into book values(162, 100, 1); +insert into book values(163, 100, 1); +insert into book values(164, 100, 1); +insert into book values(165, 100, 1); +insert into book values(166, 100, 1); +insert into book values(167, 100, 1); +insert into book values(168, 100, 1); +insert into book values(169, 100, 1); +insert into book values(170, 100, 1); +insert into book values(171, 100, 1); +insert into book values(172, 100, 1); +insert into book values(173, 100, 1); +insert into book values(174, 100, 1); +insert into book values(175, 100, 1); +insert into book values(176, 100, 1); +insert into book values(177, 100, 1); +insert into book values(178, 100, 1); +insert into book values(179, 100, 1); +insert into library_branch values(null, 'Central', 5); +insert into book_location values(100, 1, 1); +insert into book_location values(101, 1, 1); +insert into book_location values(102, 1, 1); +insert into book_location values(103, 1, 1); +insert into book_location values(104, 1, 1); +insert into book_location values(105, 1, 1); +insert into book_location values(106, 1, 1); +insert into book_location values(107, 1, 1); +insert into book_location values(108, 1, 1); +insert into book_location values(109, 1, 1); +insert into book_location values(110, 1, 1); +insert into book_location values(111, 1, 1); +insert into book_location values(112, 1, 1); +insert into book_location values(113, 1, 1); +insert into book_location values(114, 1, 1); +insert into book_location values(115, 1, 1); +insert into book_location values(116, 1, 1); +insert into book_location values(117, 1, 1); +insert into book_location values(118, 1, 1); +insert into book_location values(119, 1, 1); +insert into book_location values(120, 1, 1); +insert into book_location values(121, 1, 1); +insert into book_location values(122, 1, 1); +insert into book_location values(123, 1, 1); +insert into book_location values(124, 1, 1); +insert into book_location values(125, 1, 1); +insert into book_location values(126, 1, 1); +insert into book_location values(127, 1, 1); +insert into book_location values(128, 1, 1); +insert into book_location values(129, 1, 1); +insert into book_location values(130, 1, 1); +insert into book_location values(131, 1, 1); +insert into book_location values(132, 1, 1); +insert into book_location values(133, 1, 1); +insert into book_location values(134, 1, 1); +insert into book_location values(135, 1, 1); +insert into book_location values(136, 1, 1); +insert into book_location values(137, 1, 1); +insert into book_location values(138, 1, 1); +insert into book_location values(139, 1, 1); +insert into book_location values(140, 1, 1); +insert into book_location values(141, 1, 1); +insert into book_location values(142, 1, 1); +insert into book_location values(143, 1, 1); +insert into book_location values(144, 1, 1); +insert into book_location values(145, 1, 1); +insert into book_location values(146, 1, 1); +insert into book_location values(147, 1, 1); +insert into book_location values(148, 1, 1); +insert into book_location values(149, 1, 1); +insert into borrowed_book values(100, 1, 1, '1999-10-31', '1999-10-31'); +insert into borrowed_book values(101, 1, 2, '1999-10-31', '1999-10-31'); +insert into library_branch values(null, 'Central', 8); +insert into library_branch values(null, 'Central', 7); +insert into library_branch values(null, 'Central', 5); +insert into author values(null, "author1", null, "author1"); +insert into author values(null, "author2", null, "author2"); +insert into author values(null, "author3", null, "author3"); +insert into author values(null, "author4", null, "author4"); +insert into author values(null, "author5", null, "author5"); +insert into author values(null, "author6", null, "author6"); +insert into author values(null, "author7", null, "author7"); +insert into author values(null, "author8", null, "author8"); +insert into author values(null, "author9", null, "author9"); +insert into book_author values(101, 1); +insert into book_author values(101, 2); +insert into book_author values(102, 3); +insert into book_author values(103, 4); +insert into book_author values(104, 5); +insert into book_author values(105, 6); +insert into book_author values(106, 7); +insert into book_author values(107, 8); + + +-- select branchname, count(*) from library_branch group by branchname, branchid; + +-- insert into borrower values(null, 'akshai', 9, '456'); + commit; \ No newline at end of file diff --git a/src/test/java/net/sourceforge/schemaspy/util/RailsNamingTest.java b/src/test/java/net/sourceforge/schemaspy/util/RailsNamingTest.java index 5f506cc..04b4411 100644 --- a/src/test/java/net/sourceforge/schemaspy/util/RailsNamingTest.java +++ b/src/test/java/net/sourceforge/schemaspy/util/RailsNamingTest.java @@ -1,56 +1,56 @@ -/* - * This file is a part of the SchemaSpy project (http://schemaspy.sourceforge.net). - * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 John Currier - * - * SchemaSpy is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * SchemaSpy is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -package net.sourceforge.schemaspy.util; - -import junit.framework.TestCase; - -/** - * Simple tests to try out Ruby On Rails naming convention detection techniques. - * - * @author John Currier - */ -public class RailsNamingTest extends TestCase { - /** - * Test Rails naming convention conversion for 'table_id' to 'tables' - */ - public void testPluralize() { - // given column name should ref expected table (based on RoR conventions) - String columnName = "vaccine_id"; - String expectedTableName = "vaccines"; - - String singular = columnName.substring(0, columnName.length() - 3); - String primaryTableName = Inflection.pluralize(singular); - - assertEquals(expectedTableName, primaryTableName); - } - - /** - * Test Rails naming convention conversion for multi-word tables - */ - public void testPluralizeMultiWordTable() { - // given column name should ref expected table (based on RoR conventions) - String columnName = "active_ingredient_id"; - String expectedTableName = "active_ingredients"; - - String singular = columnName.substring(0, columnName.length() - 3); - String primaryTableName = Inflection.pluralize(singular); - - assertEquals(expectedTableName, primaryTableName); - } +/* + * This file is a part of the SchemaSpy project (http://schemaspy.sourceforge.net). + * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 John Currier + * + * SchemaSpy is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * SchemaSpy is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +package net.sourceforge.schemaspy.util; + +import junit.framework.TestCase; + +/** + * Simple tests to try out Ruby On Rails naming convention detection techniques. + * + * @author John Currier + */ +public class RailsNamingTest extends TestCase { + /** + * Test Rails naming convention conversion for 'table_id' to 'tables' + */ + public void testPluralize() { + // given column name should ref expected table (based on RoR conventions) + String columnName = "vaccine_id"; + String expectedTableName = "vaccines"; + + String singular = columnName.substring(0, columnName.length() - 3); + String primaryTableName = Inflection.pluralize(singular); + + assertEquals(expectedTableName, primaryTableName); + } + + /** + * Test Rails naming convention conversion for multi-word tables + */ + public void testPluralizeMultiWordTable() { + // given column name should ref expected table (based on RoR conventions) + String columnName = "active_ingredient_id"; + String expectedTableName = "active_ingredients"; + + String singular = columnName.substring(0, columnName.length() - 3); + String primaryTableName = Inflection.pluralize(singular); + + assertEquals(expectedTableName, primaryTableName); + } } \ No newline at end of file diff --git a/src/test/java/net/sourceforge/schemaspy/util/VersionTest.java b/src/test/java/net/sourceforge/schemaspy/util/VersionTest.java index cdc7834..a58901f 100644 --- a/src/test/java/net/sourceforge/schemaspy/util/VersionTest.java +++ b/src/test/java/net/sourceforge/schemaspy/util/VersionTest.java @@ -1,77 +1,77 @@ -/* - * This file is a part of the SchemaSpy project (http://schemaspy.sourceforge.net). - * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 John Currier - * - * SchemaSpy is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * SchemaSpy is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -package net.sourceforge.schemaspy.util; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import junit.framework.TestCase; - -/** - * @author John Currier - */ -public class VersionTest extends TestCase { - private final Version twoNineOne = new Version("2.9.1"); - private final Version twoTen = new Version("2.10"); - private final Version twoTenOne = new Version("2.10.1"); - - public void testCompareTo() { - assertTrue(twoNineOne.compareTo(twoTen) < 0); - assertTrue(twoTen.compareTo(twoTen) == 0); - assertTrue(twoTenOne.compareTo(twoTen) > 0); - - assertTrue(twoNineOne.compareTo(twoTenOne) < 0); - assertTrue(twoTen.compareTo(twoTenOne) < 0); - assertTrue(twoTenOne.compareTo(twoTenOne) == 0); - - assertTrue(twoNineOne.compareTo(twoNineOne) == 0); - assertTrue(twoTen.compareTo(twoNineOne) > 0); - assertTrue(twoTenOne.compareTo(twoNineOne) > 0); - } - - public void testEquals() { - assertTrue(twoTen.equals(twoTen)); - } - - public void testNotEquals() { - assertFalse(twoTenOne.equals(twoTen)); - } - - public void testExtract2203() { - compareEquals("2.20.3", "dot - Graphviz version 2.20.3 (Wed Oct 8 06:02:12 UTC 2008"); - } - - public void testExtractMac2222() { - compareEquals("2.22.2", "dot - graphviz version 2.22.2 (20090313.1817)"); - } - - private void compareEquals(String digits, String versionLine) - { - Version expected = new Version(digits); - String actual = getVersionDigits(versionLine); - assertEquals(expected, new Version(actual)); - } - - private String getVersionDigits(String versionLine) { - Matcher matcher = Pattern.compile("[0-9][0-9.]+").matcher(versionLine); - if (matcher.find()) - return matcher.group(); - fail("Failed to extract version digits from " + versionLine); - return null; - } -} +/* + * This file is a part of the SchemaSpy project (http://schemaspy.sourceforge.net). + * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 John Currier + * + * SchemaSpy is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * SchemaSpy is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +package net.sourceforge.schemaspy.util; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import junit.framework.TestCase; + +/** + * @author John Currier + */ +public class VersionTest extends TestCase { + private final Version twoNineOne = new Version("2.9.1"); + private final Version twoTen = new Version("2.10"); + private final Version twoTenOne = new Version("2.10.1"); + + public void testCompareTo() { + assertTrue(twoNineOne.compareTo(twoTen) < 0); + assertTrue(twoTen.compareTo(twoTen) == 0); + assertTrue(twoTenOne.compareTo(twoTen) > 0); + + assertTrue(twoNineOne.compareTo(twoTenOne) < 0); + assertTrue(twoTen.compareTo(twoTenOne) < 0); + assertTrue(twoTenOne.compareTo(twoTenOne) == 0); + + assertTrue(twoNineOne.compareTo(twoNineOne) == 0); + assertTrue(twoTen.compareTo(twoNineOne) > 0); + assertTrue(twoTenOne.compareTo(twoNineOne) > 0); + } + + public void testEquals() { + assertTrue(twoTen.equals(twoTen)); + } + + public void testNotEquals() { + assertFalse(twoTenOne.equals(twoTen)); + } + + public void testExtract2203() { + compareEquals("2.20.3", "dot - Graphviz version 2.20.3 (Wed Oct 8 06:02:12 UTC 2008"); + } + + public void testExtractMac2222() { + compareEquals("2.22.2", "dot - graphviz version 2.22.2 (20090313.1817)"); + } + + private void compareEquals(String digits, String versionLine) + { + Version expected = new Version(digits); + String actual = getVersionDigits(versionLine); + assertEquals(expected, new Version(actual)); + } + + private String getVersionDigits(String versionLine) { + Matcher matcher = Pattern.compile("[0-9][0-9.]+").matcher(versionLine); + if (matcher.find()) + return matcher.group(); + fail("Failed to extract version digits from " + versionLine); + return null; + } +}