Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 79343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:07:51+00:00 2026-05-10T21:07:51+00:00

I’m trying to grab data from a MySQL database. Approach 2 – apply/map style

  • 0

I’m trying to grab data from a MySQL database.

Approach 2 – apply/map style

I’m using the MySQL ADO Reference to try to build this system. In particular, the example found at 21.2.3.1.7.

(using a pseudo code)

let table = build_sequence(query.read) 

Where query.read returns a row in the table(Or rather, a list of elements that happen to be a row in the table). And the table variable is a list of lists that will represent a table returned from the query.

I’ve stared at the code given below, and it’s syntax is over my head, I’m afraid.

Approach 1 – looping.

Problem 1: It’s inelegant, requiring a mutable.

Problem 2: This just feels wrong, based on my prior experience with Prolog & Lisp. There’s gotta be a more…functional way to do this.

I’m not sure where to begin though. Comments & thoughts?

let reader : MySql.Data.MySqlClient.MySqlDataReader = command.ExecuteReader()  let arr = []  let mutable rowIter = 0 let readingLoop() =     while(reader.Read()) do         rowIter = rowIter + 1         for i = 0 to reader.FieldCount do              //set arr[someiterator, i] = reader.GetValue[i].ToString()) 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T21:07:52+00:00Added an answer on May 10, 2026 at 9:07 pm

    The Seq type has a neat function for handling database cursors called generate_using (see F# Manual and the Data Access chapter in Foundations of F#). This is a higher order function that takes one function to open the cursor and another (called repeatedly) to process records from the cursor. Here is some code that uses generate_using to execute a sql query:

    let openConnection (connectionName : string) =     let connectionSetting = ConfigurationManager.ConnectionStrings.Item(connectionName)     let connectionString = connectionSetting.ConnectionString     let connection = new OracleConnection(connectionString)     connection.Open()     connection  let generator<'a> (reader : IDataReader) =     if reader.Read() then         let t = typeof<'a>         let props = t.GetProperties()         let types = props                     |> Seq.map (fun x -> x.PropertyType)                     |> Seq.to_array         let cstr = t.GetConstructor(types)         let values = Array.create reader.FieldCount (new obj())         reader.GetValues(values) |> ignore         let values = values                      |> Array.map (fun x -> match x with | :? DBNull -> null | _ -> x)         Some (cstr.Invoke(values) :?> 'a)     else         None  let executeSqlReader<'a> (connectionName : string) (sql : string) : 'a list =             let connection = openConnection connectionName      let opener() =          let command = connection.CreateCommand(CommandText = sql, CommandType = CommandType.Text)         command.ExecuteReader()      let result = Seq.to_list(Seq.generate_using opener generator)              connection.Close()     connection.Dispose()     result 

    For example to list all the tables in an Oracle database we need to define a column definition type and invoke executeSqlReader as follows:

    type ColumnDefinition = {     TableName : string;     ColumnName : string;     DataType : string;     DataLength : decimal;                 }  let tableList = executeSqlReader<ColumnDefinition>     'MyDatabase'     'SELECT t.table_name, column_name, data_type, data_length FROM USER_TABLES t, USER_TAB_COLUMNS c where t.TABLE_NAME = c.table_name order by t.table_name, c.COLUMN_NAME' 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 283k
  • Answers 283k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Enabling DoubleBuffered as stax suggested above is helpful but it… May 13, 2026 at 4:21 pm
  • Editorial Team
    Editorial Team added an answer Following up on Moron's answer, You should run Process Monitor.… May 13, 2026 at 4:21 pm
  • Editorial Team
    Editorial Team added an answer I suppose, you are using beanshell library. There is no… May 13, 2026 at 4:21 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.