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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:07:13+00:00 2026-06-02T20:07:13+00:00

I am writing some tests to automate checking if a database (a MS SQL

  • 0

I am writing some tests to automate checking if a database (a MS SQL
Server instance) has certain views, and if it does not, creating those
views using the BasicTable object.
Something like:

  @Test def CheckAndBuildViewsOnDB() = { 
    VerifyViewExists(FooTable, BarTable) //FooTable et al defined as: 
FooTable extends BasicTable[Foo], where Foo is a case class & FooTable 
has a DDL create defined. 
  } 

Based on this and cribbing from Stefan Zeiger’s assertTablesExist example, I made a little method to check the db for a view, and if the
check throws an exception call that view’s BasicTable ddl.create:

  def VerifyViewExists(views:BasicTable*) = { 
    DatabaseSession.session() withSession { //helper class which 
initiates a db connection & session 
      views map { 
        v => (try queryNA[Int]("select 1 from '"+ v.tableName +"' 
where 1<0").list 
            catch {case _: Exception => v.ddl.create; 
println("Couldn't find view "+v.tableName+", creating it 
now...");}) 
      } } } 

Which seems reasonable to me, but has two problems:

  1. this isn’t the right way to type the views parameter as BasicTable,
    resulting in "error: class BasicTable takes type parameters"
  2. something funky is happening with the map argument v’s scope,
    resulting in "error: value tableName is not a member of type parameter
    T0"
    .

Pardon my ignorance with this question, as I suspect that the root of
my issue lies with not understanding Scala’s type system.
Along with those two problems is the nagging feeling that I haven’t
really done VerifyViewExists in the most succinct or readable style.

  • 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-06-02T20:07:17+00:00Added an answer on June 2, 2026 at 8:07 pm

    Since you don’t care what the type parameter is, you should be able to solve #1 by adding [_]:

    def VerifyViewExists(views:BasicTable[_]*) = { 
    

    My guess is that fixing #1 will cause #2 to disappear.

    By the way it may be better to write foreach rather than map, since the latter will collect the results into a new collection, which I don’t think you want.

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

Sidebar

Related Questions

I'm writing some unit tests for a Python library and would like certain warnings
I'm writing some load tests against a restricted web server on our local domain.
I'm writing some tests to test my sqllite database code. Can someone here explain
I am writing some tests with RSpec (tests and not specs, the code was
I'm writing some automated acceptance tests for a flash movie (driving the movie using
I'm writing some tests in Perl which have a fair amount of set up.
I'm writing some tests for a C++ command line Linux app. I'd like to
I was writing some Unit tests last week for a piece of code that
I am currently writing some unit tests for a business-logic class that includes validation
I'm writing some unit tests which are going to verify our handling of various

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.