ENH: raise exception when sqlalchemy is required for database string URI
State: closed

- I get a cryptic error `AttributeError: 'str' object has no attribute 'cursor'` if sqlalchemy is not installed and I pass a database string URI to `pandas.read_sql`. I think the error should be made more explicit.
- Also I think there is a shadowing issue with`_SQLALCHEMY_INSTALLED` in `_engine_builder`.

```
/opt/conda/lib/python3.4/site-packages/pandas/io/sql.py in read_sql_query(sql, con, index_col, coerce_float, params, parse_dates, chunksize)
    427     return pandas_sql.read_query(
    428         sql, index_col=index_col, params=params, coerce_float=coerce_float,
--> 429         parse_dates=parse_dates, chunksize=chunksize)
    430 
    431 

/opt/conda/lib/python3.4/site-packages/pandas/io/sql.py in read_query(self, sql, index_col, coerce_float, params, parse_dates, chunksize)
   1569 
   1570         args = _convert_params(sql, params)
-> 1571         cursor = self.execute(*args)
   1572         columns = [col_desc[0] for col_desc in cursor.description]
   1573 

/opt/conda/lib/python3.4/site-packages/pandas/io/sql.py in execute(self, *args, **kwargs)
   1532             cur = self.con
   1533         else:
-> 1534             cur = self.con.cursor()
   1535         try:
   1536             if kwargs:

AttributeError: 'str' object has no attribute 'cursor'
```


Labels:
name: Error Reporting
description: Incorrect or improved errors from pandas
name: IO SQL
description: to_sql, read_sql, read_sql_query

Comments:
this would need some tests

@ksindi Thanks for the catch!

For adding a test, you can put it in `TestSQLiteFallbackApi` I think (this class is not skipped if sqlalchemy is not installed), and then let the test itself skip if `SQLALCHEMY_INSTALLED` is True. 
I am only not sure if there is a test build that has no sqlalchemy installed

@jorisvandenbossche thanks. I'll change to ImportError and run tests.

@jorisvandenbossche status of this?

@jreback Haven't had a chance to work on it.

pls rebase / update

can you rebase/update

can you rebase / update

Get same error if mysql driver (e.g. mysqldb) is not installed.

@ksindi Would you have some time to update this?

@jorisvandenbossche I will get this done this week. Sorry for the delay.

## [Current coverage](https://codecov.io/gh/pydata/pandas/pull/11920?src=pr) is 85.29% (diff: 50.00%)

> Merging [#11920](https://codecov.io/gh/pydata/pandas/pull/11920?src=pr) into [master](https://codecov.io/gh/pydata/pandas/branch/master?src=pr) will decrease coverage by **<.01%**

``` diff
@@             master     #11920   diff @@
==========================================
  Files           139        139          
  Lines         50138      50140     +2   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
  Hits          42769      42769          
- Misses         7369       7371     +2   
  Partials          0          0          
```

> Powered by [Codecov](https://codecov.io?src=pr). Last update [3186fef...20678db](https://codecov.io/gh/pydata/pandas/compare/3186fef545b55ca7b4a3c79c800f32b1d586545e...20678db492d02d8a9f97f2b6e0a4edaecaee4e14?src=pr)

@jorisvandenbossche added test

@jreback not sure why getting build error. Let me know if there's anything else I need to do on my end.

pls add a whatsnew note.

you have linting errors: https://travis-ci.org/pydata/pandas/jobs/148568926
https://travis-ci.org/pydata/pandas/jobs/148568933 is failing

## What's New
- Raise ImportError when sqlalchemy is not installed and a connection string is used

@jreback thanks will fix linting error tonight

@jreback just an fyi I fixed linting errorr

lgtm. @jorisvandenbossche 

@ksindi Thanks!