Re: Euphoria MVC updates

new topic     » goto parent     » topic index » view thread      » older message » newer message

I would suggest using following function instead of url_parse():

include std/regex.e as re 
include std/pretty.e 
include std/filesys.e 
include std/sequence.e 
include std/convert.e 
include std/console.e 
--include sqlite3.e 
 
constant URLS = { 
  "http://user:pass@www.debian.org:80/index.html?name=John&age=39", 
  "http://www.debian.org:80/index.html?name=John&age=39", 
  "http://www.debian.org/index.html?name=John&age=39", 
  "http://user:pass@www.debian.org/index.html?name=John&age=39", 
  "http://user:pass@www.debian.org:80", 
  "http://user:pass@www.debian.org:80/", 
  "http://user:pass@www.debian.org:80/index.html", 
  "http://user:pass@www.debian.org/index.html", 
  "http://www.debian.org:80/index.html", 
  "http://www.debian.org/index.html", 
  "file:///D:/Data/Euphoria/v4/Personnel/mysql_users/users.sqlite" 
} 
 
constant re_url = re:new("([a-z]+):(//+)(.*)") 
 
function parse_url(sequence url) 
  sequence s = "", user="", pass="", host="", path = "", query = "" 
  integer port=0 
  object matches = re:matches(re_url, url) 
  --pretty_print(1, matches, {2}) 
  --puts(1, "\n") 
  if equal("file", matches[2]) then 
    return {matches[2], mapping(matches[4], "/", {SLASH})} 
  else 
    if find('/', matches[4]) then 
      s = stdseq:split(matches[4], '/') 
      path = s[2] 
      url = s[1] 
    else 
      url = matches[4] 
    end if 
    if find('@', url) then 
      s = stdseq:split(url, '@') 
      {user, pass} = stdseq:split(s[1], ':') 
      url = s[2] 
    end if 
    if find(':', url) then 
      s = stdseq:split(url, ':') 
      host = s[1] 
      port = to_number(s[2]) 
    else 
      host = url 
    end if 
    if find('?', path) then 
      s = stdseq:split(path, '?') 
      path = s[1] 
      query = s[2] 
    else 
    end if 
    return {matches[2], user, pass, host, port, path, query} 
  end if 
end function 
 
for i = 1 to length(URLS) do 
  puts(1, URLS[i] & "\n") 
  sequence matches = parse_url(URLS[i]) 
  pretty_print(1, matches, {2}) 
  puts(1, "\n") 
/* 

  if equal(matches[1], "file") then 
    atom db = sqlite_open( matches[2] ) 
    puts(1, "DB is opened!\n") 
    sqlite_close( db ) 
  end if 
*/ 
end for 
 
maybe_any_key() 

Using my own sqlite3 wrapper, sqlite_open() does work.

If I use openeuphoria-mvc sqlite3_open(), database opening fails.

Jean-Marc

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu