Innov-AI
    Documentation | MentDB Weak Server
Generate MQL to ETL_CSV_TO_DB on table

  • To generate MQL to ETL_CSV_TO_DB on table:
  • Right click on the table 'apps' and select 'GEN HANDLE > CSV_TO_DB'
  • in editor {
    	scrud csv_to_db "MENTDB" "apps" "/Users/jimmitry/Desktop/file.csv" "," "'" "A,B,C";
    };
  • Update the script
  • in editor {
    	scrud csv_to_db "MENTDB" "apps" "/home/jimmitry/Desktop/file.csv" "," "'" "A,B";
    };
  • Execute buttons
  • script create exe "MENTDB.apps.csv_to_db" false 1
      (param
      	(var "[csv]" {true} "The CSV file path" is_null:false is_empty:false "")
      )
      "Move data from a CSV to a table."
    {
    	
    	#To create parameters;
    	parameter add "MENTDB.APPS.CSV_TO_DB.lock" null;
    	parameter add "MENTDB.APPS.CSV_TO_DB.err" "";
    	parameter add "MENTDB.APPS.CSV_TO_DB.ts" "";
    	
    	#Execute only if not use;
    	if (parameter lock_if_null "MENTDB.APPS.CSV_TO_DB.lock" (concat "Locked by: " (who) "/" (sid))) {
    	
    		try {
    			
    			#Connection ...;
    			sql connect "session1" {cm get "MENTDB"};
    			sql auto_commit "session1" false;
    			-> "[nbToCommit]" 0;
    			
    			csv parse "T" [csv] "," "'" "A,B" {
    				
    				#CSV VARIABLE TO MATCH;
    
    				[T_A]
    				[T_B]
    
    				#INSERT REQUEST;
    				-> "[result]" (sql dml "session1" (concat 
    					"INSERT INTO public.apps (
    				app_id,
    				title
    			) VALUES (
    				" (sql encode [T_app_id]) " ,
    				" (sql encode [T_title]) "
    			);"
    				));
    
    				#UPDATE REQUEST;
    				-> "[result]" (sql dml "session1" (concat 
    					"UPDATE public.apps SET
    				app_id=" (sql encode [T_app_id]) " ,
    				title=" (sql encode [T_title]) " 
    			WHERE "
    				));
    
    				#DELETE REQUEST;
    				-> "[result]" (sql dml "session1" (concat 
    					"DELETE FROM public.apps WHERE "
    				));
    				
    				++ "[nbToCommit]";
    				
    				if (== [nbToCommit] 100) {
    					
    					sql commit "session1";
    					
    					-> "[nbToCommit]" 0;
    					
    				};
    			
    			};
    			
    			#End by commit;
    			sql commit "session1";
    			
    			#Disconnection ...;
    			sql disconnect "session1";
    			
    			parameter update "MENTDB.APPS.CSV_TO_DB.lock" null;
    			parameter update "MENTDB.APPS.CSV_TO_DB.err" "";
    			parameter update "MENTDB.APPS.CSV_TO_DB.ts" "";
    			
    			"OK"
    			
    		} {
    			
    			parameter update "MENTDB.APPS.CSV_TO_DB.lock" null;
    			parameter update "MENTDB.APPS.CSV_TO_DB.err" [err];
    			parameter update "MENTDB.APPS.CSV_TO_DB.ts" (date systimestamp);
    		
    			#Close the connection;
    			try {sql disconnect "session1"} {} "[sub_err]";
    			
    			#Generate an error;
    			exception (1) ([err]);
    			
    		} "[err]";
    	
    	} {
    		
    		parameter get value "MENTDB.APPS.CSV_TO_DB.lock";
    		
    	}
    	
    } "Return nothing.";
  • Update the script and save:
  • Execute buttons
Services     Supporters     Contact     About     Legal notice © 2024