Creating MySQL Databases

Mark Wieder mwieder at ahsoftware.net
Sun Mar 20 22:04:11 EST 2005


Peter-

Here's what I do (extract) to create MySQL databases from within
runrev. Send the commands to a text file, then execute the MySQL
client using the text file as a command script:

on CreateDatabase
  local strFileName, myError

  -- CreateDatabase asks for a name for the temporary output file
  -- and then uses the contents of field "dbName" to construct
  -- a MySQL script to create a database.
  
  ask file "Temporary script File:"
  if it is not empty then
    put it into strFileName
    open file strFileName for write
    if the last char of field "dbName" is cr then
      delete the last char of field "dbName"
    end if

    write "DROP DATABASE IF EXISTS" && field "dbName" & ";" & cr to file strFileName
    write "CREATE DATABASE" && field "dbName" & ";" & cr to file strFileName
    write "USE" && field "dbName" & ";" & cr & cr to file strFileName
    close file strFileName
    put LaunchDB(strFileName) into myError
  end if
end CreateDatabase

function LaunchDB strSQLFile, strDBName, strUserName, strPassword
  local blnSuccess, strSourceFile, strDBExecutable
  
  put empty into blnSuccess
  if the platform is "MacOS" then
    set the shellCommand to "/bin/csh"
  end if
  -- I have previously stored the path to the MySQL client
  -- in a custom property called cMySQLLocation, but obviously
  -- you could do something different here.
  put the cMySQLLocation of stack gDialogStack into strDBExecutable
  if strSQLFile is not empty then
    put "<" && quote & strSQLFile & quote into strSourceFile
    put shell(strDBExecutable && strDBName && strUserName && strPassword && strSourceFile) into blnSuccess
  end if
  return blnSuccess
end LaunchDB

-- 
-Mark Wieder
 mwieder at ahsoftware.net



More information about the use-livecode mailing list