Search notes:

VBA Module SQL [Database]

The following SQL VBA modules currently has two functions:
sqlStatementsOfFile relies on slurpFileCharSet which can be found here.
The function, in turn, is needed by the sub RunSQLScripts() which runs the statements found in a file in an Access database.
option explicit

public function removeSQLComments(sqlText as string) as string ' {
'
'   http://stackoverflow.com/a/1839290/180275
'
'   Needs Regexp refereence reference:
'       call application.VBE.activeVBProject.references.addFromGuid("{3F4DACA7-160D-11D2-A8E9-00104B365C9F}", 5, 5)
'
'   TODO: Currently removes -- only, but should also
'   remove /* ... */

  dim re as new regExp

  re.pattern   = "--.*$"
  re.global    = true
  re.multiLine = true

  removeSQLComments = re.replace(sqlText, "")

end function ' }

public function sqlStatementsOfFile(pathToScript as string, optional charSet as string = "utf-8") as string() ' {

   dim sqlText as string

 ' Find slurpFileCharSet() @ https://renenyffenegger.ch/notes/development/languages/VBA/modules/Common/File
   sqlText = slurpFileCharSet(pathToScript, charSet)
 
   sqlText = removeSQLComments(sqlText)

   dim sqlStatements() as string

 '
 ' This is of course shaky, at best, but up to
 ' now, it did the job:
 '
   sqlStatementsOfFile = strings.split(sqlText, ";")

end function ' }
Github repository VBAModules, path: /Database/SQL.bas

See also

VBA regular expression to remove SQL comments.
René's VBA Modules

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1759406151, '216.73.216.42', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/VBA/modules/Database/SQL(91): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78