Created
October 10, 2013 12:56
-
-
Save OnorioCatenacci/6917875 to your computer and use it in GitHub Desktop.
Revisions
-
OnorioCatenacci created this gist
Oct 10, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ open System open System.Data.Odbc open System.Windows.Forms let connectToAccess filename = let connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;FileDSN=" + filename + ";User Id=admin;Password=;" new OdbcConnection(connectionString) let connectToDb() = let userProfileDir = Environment.GetEnvironmentVariable("UserProfile") let accessFile = userProfileDir + @"\Documents\FortuneCookie.accdb" connectToAccess accessFile let pasteStringToClipboard string = Clipboard.SetText string let buildQuoteString quote author = sprintf "%s\n -- %s" quote author let getRandomQuote()= let connection = connectToDb() let tableName = "FortuneCookieQuotes" //Note: the order by clause has to be in the order it is or you get the same quote repeatedly let randomQuoteSQL = "SELECT TOP 1 ID,FortuneCookieText,CreditedTo FROM " + tableName + " ORDER BY LastUsed ASC, RND(ID)" let getQuoteCommand = new OdbcCommand(randomQuoteSQL,connection) connection.Open() let result = getQuoteCommand.ExecuteReader() let ableToReadResult = result.Read() let s = buildQuoteString (result.["FortuneCookieText"] :?> string) (result.["CreditedTo"] :?> string) let quoteID = result.["ID"] :?> int let updateQuoteSQL = "UPDATE " + tableName + " SET LastUsed = '" + DateTime.Now.ToString("d") + "' WHERE ID = " + quoteID.ToString() let updateResultCommand = new OdbcCommand(updateQuoteSQL,connection) let updateResult = updateResultCommand.ExecuteNonQuery() connection.Close() s [<STAThread>] let main (argv:string[]) = let quote = getRandomQuote() pasteStringToClipboard quote 0 main fsi.CommandLineArgs;;