Lasso Soft Inc. > Home

[clean_lasso_database]

Linkclean_lasso_database
AuthorMarc Vos
CategoryAdministration
Version8.5.x
LicensePublic Domain
Posted14 Feb 2013
Updated14 Feb 2013
More by this author...

Description

Read more here: http://marc.vos.net/howto/cleanlasso/

Sample Usage

http://127.0.0.1/clean_lasso_database.lasso

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.

[

auth_admin; 

var('zzsql' = '',
	'svdb' = '',
	'delflag' = false
	);

// Get the list of TEMP tables currently in Lasso
$zzsql = "
	select
		d.name as dbname, 
		t.id as tblid, 
		t.name as tblname 
	from security_database_tables t 
	join security_datasource_databases d on d.id=t.id_database 
	where 
		t.name like 'REP%'
	order by
		d.name, t.id";
	
inline(-database='lasso_internal', -sql=$zzsql, -maxrecords='all');
	records;
		$delflag = false;
		
		if($svdb != field('dbname'));
			// Get the list of tables currently in MySQL + their last update date
			$zzsql = "
				show table status 
				from " + field('dbname') + " 
				like 'REP%'";
				
			inline(-Host=Array(-datasource='mysqlds', -name='127.0.0.1', -username='lasso', -password='secret'), -sql=$zzsql, -maxrecords='all');
				var('in_mysql' = records_map);
			/inline;
			
			$svdb = field('dbname');
		/if;
		
		// Check if Lasso-defined table still present in MySQL.
		// If not, delete all references from Lasso
		if($in_mysql->find(field('tblname'))->size == 0);
			$delflag = true;
		else(date_difference($in_mysql->find(field('tblname'))->find('Update_time'), date, -day) < -2);	// Older than 2 days = delete
			// Remove table from MySQL
			$zzsql = 'drop table ' + field('dbname') + '.' + field('tblname');
			inline(-Host=Array(-datasource='mysqlds', -name='127.0.0.1', -username='lasso', -password='secret'), -sql=$zzsql);
			/inline;

			$delflag = true;
		/if;
		
		if($delflag);
			// Delete all security_table_fields entries
			$zzsql = 'delete from security_table_fields where id_table=' + field('tblid');
			inline(-sql=$zzsql); /inline;
			
			// Delete all security_group_table_map entries
			$zzsql = 'delete from security_group_table_map where id_table=' + field('tblid');
			inline(-sql=$zzsql); /inline;
			
			// Delete the security_database_tables entry
			$zzsql = 'delete from security_database_tables where id=' + field('tblid');
			inline(-sql=$zzsql); /inline;
		/if;
	/records;
/inline;

]

Comments

No comments

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