Home > FMAToolbox > Database > DBCreate.m

DBCreate

PURPOSE ^

DBCreate - Create database.

SYNOPSIS ^

function database = DBCreate(database)

DESCRIPTION ^

DBCreate - Create database.

 Create database with figure and variable tables. Use this function
 if you have admin rights to the database server. Otherwise ask
 the DBA to create an empty database with the appropriate access
 rights, and then use <a href="matlab:help DBCreateTables">DBCreateTables</a> to create the actual tables in
 the database.

  USAGE

    name = DBCreate(database)

    database       database name (see NOTE below)

  NOTE

    Database names can include wildcards to indicate current date and time:

      %y    year
      %m    month
      %d    day
      %t    time

  EXAMPLE

    DBCreate('TestData_%y%m%d');

  SEE

    See also DBCreateTables, DBRemove.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function database = DBCreate(database)
0002 
0003 %DBCreate - Create database.
0004 %
0005 % Create database with figure and variable tables. Use this function
0006 % if you have admin rights to the database server. Otherwise ask
0007 % the DBA to create an empty database with the appropriate access
0008 % rights, and then use <a href="matlab:help DBCreateTables">DBCreateTables</a> to create the actual tables in
0009 % the database.
0010 %
0011 %  USAGE
0012 %
0013 %    name = DBCreate(database)
0014 %
0015 %    database       database name (see NOTE below)
0016 %
0017 %  NOTE
0018 %
0019 %    Database names can include wildcards to indicate current date and time:
0020 %
0021 %      %y    year
0022 %      %m    month
0023 %      %d    day
0024 %      %t    time
0025 %
0026 %  EXAMPLE
0027 %
0028 %    DBCreate('TestData_%y%m%d');
0029 %
0030 %  SEE
0031 %
0032 %    See also DBCreateTables, DBRemove.
0033 %
0034 
0035 % Copyright (C) 2007-2013 by Michaƫl Zugaro
0036 %
0037 % This program is free software; you can redistribute it and/or modify
0038 % it under the terms of the GNU General Public License as published by
0039 % the Free Software Foundation; either version 3 of the License, or
0040 % (at your option) any later version.
0041 
0042 % Make sure MyM is installed and functional
0043 CheckMyM;
0044 
0045 % Check parameters
0046 if nargin < 1,
0047   error('Incorrect number of parameters (type ''help <a href="matlab:help DBCreate">DBCreate</a>'' for details).');
0048 end
0049 if ~isastring(database),
0050   error('Incorrect database name (type ''help <a href="matlab:help DBCreate">DBCreate</a>'' for details).');
0051 end
0052 
0053 % Insert date
0054 database = InsertDate(database);
0055 
0056 % Create database
0057 try
0058     h = mym(['create database ' database]);
0059 catch
0060    error('FMAToolbox:DBCreate:cannotCreateDB',['Could not create database ''' database '''.\nThis database might already exist or its name may contain incorrect characters (e.g. ''-'').\nAlternatively, you may not have the appropriate access rights, in which case you may want\nto ask your DBA to create an empty database for you, and then use <a href="matlab:help DBCreateTables">DBCreateTables</a> to create\nthe tables in the database.']);
0061 end
0062 
0063 h = mym(['use ' database]);
0064 
0065 % Create tables
0066 try
0067     h = mym('create table figures (eid varchar(50),name varchar(100),comments varchar(255),parameters varchar(50),mfiles mediumblob,code mediumblob,date varchar(50),user varchar(15),md5 varchar(32),gid smallint unsigned,fig mediumblob,png mediumblob,primary key (eid,name));');
0068     h = mym('create table variables (eid varchar(50),name varchar(100),comments varchar(255),parameters varchar(50),mfiles mediumblob,code mediumblob,date varchar(50),user varchar(15),md5 varchar(32),gid smallint unsigned,v longblob,primary key (eid,name));');
0069 catch
0070    error(['Could not create tables in ''' database '''.']);
0071 end

Generated on Fri 16-Mar-2018 13:00:20 by m2html © 2005