function SendToPsql, sql_cmd, host, user, database, schema = schema, column = column, debug = debug DEBUG = keyword_set(debug) column = '' ; Ajout d'un backslash avant tous les guillemets double sql_cmd = strjoin(strsplit(sql_cmd, '"', /extract), '\"') host_flag = '' if (keyword_set(host) and (host ne 'localhost')) then begin host_flag = ' -h ' + host endif schema_cmd = '' if (keyword_set(schema) and (schema ne 'public')) then begin schema_cmd = ' SET search_path = ' + schema + ' , public, pg_catalog; ' endif cmd = 'psql' + host_flag + ' -U ' + user + ' ' + database + $ ' -c "' + schema_cmd + sql_cmd + '"' if (DEBUG eq 1) then print, cmd spawn, cmd, result if (DEBUG eq 1) then print, result if (strpos(strupcase(strtrim(sql_cmd,2)),'SELECT') eq 0) then begin if (n_elements(result) le 4) then begin return, -1 endif first_line = strtrim(strsplit(result[0], "|", /extract),2) column = first_line res = strarr(n_elements(first_line), n_elements(result)-4) for i=2L, n_elements(result)-3 do begin res[*,i-2] = strtrim(strsplit(result[i], "|", /extract),2) endfor endif else begin if (strpos(strupcase(strtrim(result[0],2)),'ERROR') ne -1) then begin res = -1 endif else begin res = result endelse endelse return, res end