Home > FMAToolbox > Database > DBDuplicate.m

DBDuplicate

PURPOSE ^

DBDuplicate - Duplicate database.

SYNOPSIS ^

function new = DBDuplicate(old,new,varargin)

DESCRIPTION ^

DBDuplicate - Duplicate database.

  USAGE

    name = DBDuplicate(old,new)

    old            database to duplicate
    new            new 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

    DBDuplicate('TestData_20130215','TestData_%y%m%d');

  SEE

    See also DBCreate, DBMerge.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function new = DBDuplicate(old,new,varargin)
0002 
0003 %DBDuplicate - Duplicate database.
0004 %
0005 %  USAGE
0006 %
0007 %    name = DBDuplicate(old,new)
0008 %
0009 %    old            database to duplicate
0010 %    new            new database name (see NOTE below)
0011 %
0012 %  NOTE
0013 %
0014 %    Database names can include wildcards to indicate current date and time:
0015 %
0016 %      %y    year
0017 %      %m    month
0018 %      %d    day
0019 %      %t    time
0020 %
0021 %  EXAMPLE
0022 %
0023 %    DBDuplicate('TestData_20130215','TestData_%y%m%d');
0024 %
0025 %  SEE
0026 %
0027 %    See also DBCreate, DBMerge.
0028 %
0029 
0030 % Copyright (C) 2007-2016 by Michaƫl Zugaro
0031 %
0032 % This program is free software; you can redistribute it and/or modify
0033 % it under the terms of the GNU General Public License as published by
0034 % the Free Software Foundation; either version 3 of the License, or
0035 % (at your option) any later version.
0036 
0037 % Make sure MyM is installed and functional
0038 CheckMyM;
0039 
0040 % Check parameters
0041 if nargin < 2,
0042   error('Incorrect number of parameters (type ''help <a href="matlab:help DBDuplicate">DBDuplicate</a>'' for details).');
0043 end
0044 if ~isastring(old),
0045   error('Incorrect old database name (type ''help <a href="matlab:help DBDuplicate">DBDuplicate</a>'' for details).');
0046 end
0047 if ~isastring(new),
0048   error('Incorrect new database name (type ''help <a href="matlab:help DBDuplicate">DBDuplicate</a>'' for details).');
0049 end
0050 
0051 % Insert date
0052 new = InsertDate(new);
0053 
0054 % Make sure old database exists
0055 current = DBUse;
0056 try
0057     DBUse(old);
0058 catch
0059   error(['Database ''' old ''' not found (type ''help <a href="matlab:help DBDuplicate">DBDuplicate</a>'' for details).']);
0060 end
0061 % Create new database
0062 DBCreate(new);
0063 if ~isempty(current), DBUse(current); end
0064 
0065 % Copy database
0066 try
0067     h = mym(['insert into ' new '.' 'figures select * from ' old '.figures']);
0068     h = mym(['insert into ' new '.' 'variables select * from ' old '.variables']);
0069     % Copy external storage if necessary
0070     storage = DBExternalStoragePath;
0071     sourceDirectory = [storage '/' old];
0072     targetDirectory = [storage '/' new];
0073     if ~copyfile(sourceDirectory,targetDirectory),
0074        error(['Could not copy external storage for database ''' new '''.']);
0075     end
0076 catch
0077    error('FMAToolbox:DBDuplicate:copyDB',['Could not copy database ''' new '''.']);
0078 end

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