Innov-AI
    Documentation | MentDB Weak Server
Read a SQL Database and write a CSV file

  • Method 1:
  • try {
    
    	sql connect "session1" {cm get "demo_cm_mysql";};
    
    	-> "[CSV]" "A;B;C";
    	sql parse "session1" "T" (concat "select id, name, quantity from products") {
    	
    		concat_var "[CSV]" [_n_];
    		concat_var "[CSV]" (string csv_value [T_id] ";" "'") ";";
    		concat_var "[CSV]" (string csv_value [T_name] ";" "'") ";";
    		concat_var "[CSV]" (string csv_value [T_quantity] ";" "'");
    	
    	};
    
    	file create "data/file.csv" [CSV];
    
    	sql disconnect "session1";
    
    } {
    
    	try {sql disconnect "session1";} {} "[err]";
    
    } "[err]";
  • Method 2:
  • try {
    
    	sql connect "session1" {cm get "demo_cm_mysql";};
    	file writer_open "w1" "data/file.csv" false TEXT "utf-8";
    	
    	file writer_add_line "w1" "A;B;C";
    
    	sql parse "session1" "T" (concat "select id, name, quantity from products") {
    	
    		-> "[CSV]" "";
    		concat_var "[CSV]" [_n_];
    		concat_var "[CSV]" (string csv_value [T_id] ";" "'") ";";
    		concat_var "[CSV]" (string csv_value [T_name] ";" "'") ";";
    		concat_var "[CSV]" (string csv_value [T_quantity] ";" "'");
    
    		file writer_add_line "w1" [CSV];
    		file writer_flush "w1";
    	
    	};
    
    	file writer_close "w1";
    	sql disconnect "session1";
    
    } {
    
    	try {file writer_close "w1";} {} "[err]";
    	try {sql disconnect "session1";} {} "[err]";
    
    } "[err]";
Services     Supporters     Contact     About     Legal notice © 2024