[admin_createdatabase]

Description

Link: [admin_createdatabase]
Author: Jason Huck
Category: Administration
Version: 8.x
License:
Posted: Nov. 21, 2006
Updated: Jan. 01, 0001
More by this author...
Creates a new database on the selected host and enables it in SiteAdmin. Requires [host_id] and authentication as a user with permissions on Lasso's internal db's, i.e., with [auth_admin]. Works for any datasource which supports CREATE DATABASE in SQL.

Parameters

-host string, required The name or alias of the host on which to create the new database.
-name string, required The name of the database to be created.

Sample Usage

admin_createdatabase(
	-host='Local MySQL',
	-name='TestDB'
);
						

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
define_tag(
	'createdatabase',
	-namespace='admin_',
	-req='host',
	-req='name', -copy,
	-priority='replace',
	-description='Creates a new database on the selected host and enables it in SiteAdmin.'
);
	#name = encode_sql(#name);

	inline( -database='lasso_internal', -sql='SELECT 1');
		// make sure name is unique
		local('sql' = '
			SELECT id 
			FROM security_datasource_databases 
			WHERE name = \'' + #name + '\'
				OR alias = \'' + #name + '\'
		');
		
		inline( -sql=#sql);
			found_count ? return(false);
		/inline;
		
		// get the host id
		local('hostID') = host_id(#host);
	
		// find an enabled database on this host to use for the connection
		local('sql' = '
			SELECT alias, name
			FROM security_datasource_databases
			WHERE id_host = ' + #hostID + '
				AND enabled = \'Y\'
			LIMIT 1
		');
		
		inline( -sql=#sql);
			found_count ?
				local('accessDB') = (field('alias') != '' ? field('alias') | field('name'))
				| return(false);
		/inline;
		
		// create the database
		local('sql' = 'CREATE DATABASE ' + #name);
		
		protect;
			inline( -database=#accessdb, -sql=#sql); /inline;
			
			// get the connector ID for the host so we can refresh it
			local('sql' = '
				SELECT id_datasource 
				FROM security_datasource_hosts 
				WHERE id = ' + #hostID + '
			');
			
			inline( -sql=#sql);
				found_count ? local('connector') = integer(field('id_datasource')) | return(false);
			/inline;
			
			admin_reloaddatasource(#connector);
			
			// enable the new database
			local('sql' = '
				UPDATE security_datasource_databases
				SET enabled = \'Y\'
				WHERE name = \'' + #name + '\'
			');
			
			inline( -sql=#sql); /inline;
			
			return(true);
		
			handle_error;
				return(false);
			/handle_error;
		/protect;
	/inline;
/define_tag;

 

Related Tags



Comments

02/06/2009, Stefan Straakenbroek
Bug fix
You should add another call to admin_reloaddatasource() after you enable the database, in order to make to table contents available to the site process. If you don't do this, the site process will display an HTTP Authentication window when trying to access a table in the database.
Email:


Password:



Newest

Most Popular

Support tagSwap.net