Lasso Soft Inc. > Home


AuthorJason Huck
Posted21 Nov 2006
Updated21 Nov 2006
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.

Sample Usage

	-host='Local MySQL',

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.

	-req='name', -copy,
	-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);
		// 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);
		// create the database
		local('sql' = 'CREATE DATABASE ' + #name);
			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);
			// enable the new database
			local('sql' = '
				UPDATE security_datasource_databases
				SET enabled = \'Y\'
				WHERE name = \'' + #name + '\'
			inline( -sql=#sql); /inline;

Related Tags


06 Feb 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.

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home



©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft