Solved

find a needle in a haystack using sql lite

Posted on 2013-11-16
7
352 Views
Last Modified: 2013-11-24
using sql lite want to find a needle in a haystack

many tables and many columns in those tables

I want to find 'bob'

Is there a query or query tool to do this search

I do not want to do a large task that involves copy paste.

I have done this task with one query in sql server
0
Comment
Question by:rgb192
  • 3
  • 2
  • 2
7 Comments
 
LVL 23

Expert Comment

by:David
Comment Utility
Conceptually, if you were using all XML or SQLText (binary) columns, my guess is that it's doable.  With OLTP, B-tree traditional systems (unindexed varchar datatypes), that becomes an exercise in futility.  IMHO, your results may vary.  

You're in effect asking, for 1..n tables in 1..n schemas, each having 1..n columns, make a pass each time through all rows in a given schema.table.column, searching for "%X%".
Then there's the possibility that the desired tuple exists but in a schema.table to which you are denied access.
0
 
LVL 38

Assisted Solution

by:Jim P.
Jim P. earned 333 total points
Comment Utility
If this is a single database it should be doable.

I'm not familiar with SQL Lite but the general idea is that there is going to be some sort of central table that lists off the rest of the tables in the DB. And you can write to a temporary table.

So it would be some sort of create temp table:
create #temptable(
     TableName as varchar(100),
     ColumnName as varchar(100),
     ColUmnValue as varchar(500))

Open in new window


Then create some sort cursor/wrapper from the system table:
cursor = select TableName from SysTables

Open in new window


Then some sort of tracking that it goes through the columns looking for 'bob':
While I < TableNameColumn.Count
RecExists = select count(*) from Cursor.TableName where Column(I) like '%' + 'bob' + '%'
     if RecExists >0 then
          INSERT INTO #temptable select TableNameColumn, Column(I).Name, Column(I).Value  from Cursor.TableName where Column(I) like '%' + 'bob' + '%'
     end if
Next I

Open in new window


Then you present the  #temptable to the user. This is the concept behind how to do it.
0
 
LVL 23

Expert Comment

by:David
Comment Utility
Jimkin, assuming that this query ran as a sys level user, what kind of resource consumption do you think this would take?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 38

Assisted Solution

by:Jim P.
Jim P. earned 333 total points
Comment Utility
I have a similar script for SQL Server DB's. Running it as the SA user on 40GB DB with about 150 tables average of 30K rows it took about 4-5 minutes.

I wouldn't want to run it in major hours for a large DB online. But it shouldn't be too horrible.
0
 

Author Comment

by:rgb192
Comment Utility
http://www.experts-exchange.com/Database/Miscellaneous/Q_28295935.html#a39654050

I do not understand syntax of step2:
cursor = select TableName from SysTables


I do not understand the other comments.
More data:
I am looking at main.db which skype uses.
I have used sql lite to view/modify tables.
Could I use another database?
0
 
LVL 23

Accepted Solution

by:
David earned 167 total points
Comment Utility
The pseudo-syntax says, take a one-dimensional temporary array in memory, and populate it with n number of table names from a schema.  Then, loop through the array: for each table name, perform some dependent transaction (query).

It's my opinion that jimpen may be simplifying his/her process for your clarity.  I observe that the logic does not handle multiple schemas (accounts that own database objects).  In one of my systems, the number of schemas is 3-4 thousand,  The SYS schema owns over fifty thousand tables.

My point is, if you're looking for 'bob' in one or two schemas, the search is indeed doable, beyond that it is not scalable.
0
 

Author Closing Comment

by:rgb192
Comment Utility
Thank you for a blueprint of what to do in sql lite.  I will use this information.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Database tuning – How to start and what to tune. This question is frequently asked by many people, both online and offline. There is no hard and fast rule-of-thumb for performance tuning, however, before beginning the tuning process one should a…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now