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 781635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:15:45+00:00 2026-05-14T20:15:45+00:00

I have a function that will create a select where clause, but right now

  • 0

I have a function that will create a select where clause, but right now everything has to be a string.

I would like to look at the variable passed in and determine what type it is and then treat it properly.

For example, numeric values don’t have single quotes around them, option type will either be null or have some value and boolean will actually be zero or one.

member self.BuildSelectWhereQuery (oldUser:'a)  =  //'
    let properties = List.zip oldUser.ToSqlValuesList sqlColumnList 
    let init = false, new StringBuilder()
    let anyChange, (formatted:StringBuilder) = 
        properties |> Seq.fold (fun (anyChange, sb) (oldVal, name) ->
            match(anyChange) with
            | true -> true, sb.AppendFormat(" AND {0} = '{1}'", name, oldVal)
            | _ -> true, sb.AppendFormat("{0} = '{1}'", name, oldVal)
        ) init
    formatted.ToString()

Here is one entity:

type CityType() =
    inherit BaseType()
    let mutable name = ""
    let mutable stateId = 0
    member this.Name with get() = name and set restnameval=name <- restnameval
    member this.StateId with get() = stateId and set stateidval=stateId <- stateidval
    override this.ToSqlValuesList = [this.Name; this.StateId.ToString()]

So, if name was some other value besides a string, or stateId can be optional, then I have two changes to make:

  1. How do I modify ToSqlValuesList to
    have the variable so I can tell the
    variable type?
  2. How do I change my select function
    to handle this?

I am thinking that I need a new function does the processing, but what is the best FP way to do this, rather than using something like typeof?

  • 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. Editorial Team
    Editorial Team
    2026-05-14T20:15:46+00:00Added an answer on May 14, 2026 at 8:15 pm

    I think that one clear functional approach would be to define a data type that represents the various (more complicated situations) that you need to handle. You mentioned that a value may be optional and that you need to distinguish numeric and textual values (for the encoding to SQL).

    You could define a discriminated union (if there are other cases that you’d like to handle, the definition may be a bit more complicated):

    type SqlValue = 
      | Missing
      | Numeric of string
      | Textual of string
    

    Note that the Textual case also carries string, because I assume that the client who produces the value takes care of converting it to string – this is only information for your SQL query generator (so that it knows whether it needs to add quotes).

    Your ToSqlValuesList member would return a list of values string & SqlValue, so for example, a sample product could be represented using the following list:

    columns = [ "Name"; "Price"; "Description" ]
    values = [ Textual("Tea"); Numeric(10); Missing ]
    

    In the code that generates the SQL query, you’d use pattern matching to handle all the different cases (most importantly, encode string to avoid SQL injection in case the value is Textual :-)).

    EDIT You’d need to implement the conversion from the specific data types to the SqlValue representation in every client. However, this can be simplified by writing a utility type (using the fact that members can be overloaded):

    type SqlValue with 
      static member From(a:int) = Numeric(a.ToString())
      static member From(a:int option) = 
        match a with None -> Missing | Some(n) -> SqlValue.From(n)
      // ... similarly for other types
    

    In the implementation of ToSqlValuesList, you would write SqlValue.From(description) and it would deal with the details autoamtically.

    A more sophisticated approach would be to annotate public members of the types representing your data entities with .NET attributes and use Reflection to extract the values (and their types) at runtime. This is more advanced, but quite elegant (there is a nice exmaple of this technique in Don Syme’s Expert F# book)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 491k
  • Answers 491k
  • 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 Freakishly, I think you are trying to pass values (in… May 16, 2026 at 10:01 am
  • Editorial Team
    Editorial Team added an answer its already there for you to use. try to run… May 16, 2026 at 10:01 am
  • Editorial Team
    Editorial Team added an answer Have you run into issues dynamically resizing based on dataset… May 16, 2026 at 10:01 am

Trending Tags

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

Top Members

Related Questions

I have a function that has a very useful name: has_useful_state(param) . I have
I want to create generic function that will need only parameter as Stored procedure
I'm trying to create a query on SQL server 2005 that will check if
I have written a function that takes two arguments and returns a SETOF result.
I have a navigation menu that has submenus slide down on hover. The menu
I am trying to create a small function that returns the number of spaces
I have some predicates being dynamically built that have the following signature passes through
I have certain initializing functions that I use to set up audit logging on
I have written the following function to calculate a check digit in R. verhoeffCheck
We are having a problem in our test and dev environments with a function

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.