473,412 Members | 2,994 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Searching a small file database

I don't want to use a db manager, like mysql, for such a small
database but I'm finding this trickier than I thought and hope someone
can provide some guidance.

I have a restaurant menu with prices and other info in a small file.
It's set up in a YAML-ish style, if you're familiar with that format.
I'm just looking for some ideas on the best way to retrieve data based
on a "keyword". What complicates things for me is that some of these
keywords might be inside a nested block, such as "prices:".

-navigation
link: link1
link: link2
-menu
chicken:
-roasted
-fried
steak:
-strip
prices:
small: 15.00
medium: 17.00
large: 19.00
-sirloin
prices:
small: 15.00
fish:
-location

In the above example, indentation matters. I am not bound by this
format so better ideas are welcome, but searching for menu->steak-
>strip->prices->large returning "19.00" seems logical to me.
What complicates things is when I want to do something like
"next_record()". It must tell me there are no more prices in "strip"
and not mistakenly search into the "prices" records of "sirloin".

Is my whole concern my answer, too? That I am trying to write a small
db manager and it's not a simple solution? Or is there simply a
better idea I'm missing?

Originally I did this in XML but felt parsing the tags wasn't any
easier and my format, above, is more readable. I can't just store a
struct in the file because I want it to be editable with any text
editor.

Thanks,
Doc
Jun 27 '08 #1
9 1883
drhowarddrfine wrote:
I don't want to use a db manager, like mysql, for such a small
database but I'm finding this trickier than I thought and hope someone
can provide some guidance.

I have a restaurant menu with prices and other info in a small file.
It's set up in a YAML-ish style, if you're familiar with that format.
[...]
I'm not, but Google is. It seems that libraries for dealing
with YAML in several programming languages, including C, have
already been written. Use one of them.

--
Er*********@sun.com
Jun 27 '08 #2
On Jun 24, 11:42*am, Eric Sosman <Eric.Sos...@sun.comwrote:
drhowarddrfine wrote:
I don't want to use a db manager, like mysql, for such a small
database but I'm finding this trickier than I thought and hope someone
can provide some guidance.
I have a restaurant menu with prices and other info in a small file.
It's set up in a YAML-ish style, if you're familiar with that format.
[...]

* * *I'm not, but Google is. *It seems that libraries for dealing
with YAML in several programming languages, including C, have
already been written. *Use one of them.

--
Eric.Sos...@sun.com
But it's not YAML. I don't know that I want to take the time to learn
all of YAML or its libraries. Perhaps because I'm in a bit of a rush
to get this part done. I feel a need to learn how to do this, too,
and not have some library do this for me.
Jun 27 '08 #3
drhowarddrfine wrote:
On Jun 24, 11:42 am, Eric Sosman <Eric.Sos...@sun.comwrote:
>drhowarddrfine wrote:
>>I don't want to use a db manager, like mysql, for such a small
database but I'm finding this trickier than I thought and hope someone
can provide some guidance.
I have a restaurant menu with prices and other info in a small file.
It's set up in a YAML-ish style, if you're familiar with that format.
[...]
I'm not, but Google is. It seems that libraries for dealing
with YAML in several programming languages, including C, have
already been written. Use one of them.

But it's not YAML. I don't know that I want to take the time to learn
all of YAML or its libraries. Perhaps because I'm in a bit of a rush
to get this part done. I feel a need to learn how to do this, too,
and not have some library do this for me.
Then your problem seems to be more about algorithms than
about the language you implement them in. Seriously: Your
questions to this point would be the same whether you were
implementing in C or Java or Lisp or assembly -- which is
a pretty good indication that they've been addressed to the
wrong forum. (Fora, actually, because I notice you've multi-
posted to at least two newsgroups. Consider your wrist slapped.)

I don't know where to refer you, other than to the YAML
documentation and/or to studying the YAML sources. Yes, I
heard your "it's not YAML," but you said it was "YAML-ish"
so you ought to be able to get some ideas, at least.

Also, you'll need to develop a more precise description of
your format than "YAML-ish but not YAML" before you can even
begin to parse and search it. Remember Douglas Adams' line
about a beverage "almost, but not quite exactly, unlike tea?"
That's how your description reads at the moment, and computers
lack sufficient imagination to fill in the details on their own.

--
Er*********@sun.com
Jun 27 '08 #4

"drhowarddrfine" <ro*******@gmail.comwrote in message
news:63**********************************@2g2000hs n.googlegroups.com...
I have a restaurant menu with prices and other info in a small file.
-navigation
link: link1
link: link2
-menu
chicken:
-roasted
-fried
steak:
-strip
prices:
small: 15.00
medium: 17.00
large: 19.00
-sirloin
prices:
small: 15.00
fish:
-location

In the above example, indentation matters. I am not bound by this
format so better ideas are welcome, but searching for menu->steak-
>>strip->prices->large returning "19.00" seems logical to me.

What complicates things is when I want to do something like
"next_record()". It must tell me there are no more prices in "strip"
and not mistakenly search into the "prices" records of "sirloin".

Is my whole concern my answer, too? That I am trying to write a small
db manager and it's not a simple solution? Or is there simply a
better idea I'm missing?
Are you sure you really want to use C? This looks an ideal job for a rapid
development language. I had a go at this using a toy language, and the
result, which possibly might be helpful, follows below (this code is not
case-sensitive and ! is like a // comment).

If you are going to use C, this code at least shows that you don't need
complex data structures like trees or linked lists; a linear set of records
is stored (or you could use 3 parallel arrays), but the indent level has to
be stored (as 1+). (Because, how large will a restaurant menu ever be?)

This uses a modified form of your menu: no "-" or ":" characters (whatever
they meant), and each indentation is a definite number of "\t" characters
(relying on multiples of 3 spaces might be iffy).

The next_record() function here (as findnext()), will also return any (index
to) records at the same or higher level than current.

Hope this helps.

---------------------------------

type rmenuitem = record(var level,name,value)

var menuitems
var currindex

PROC START=
if not readmenu("menu") then stop fi

forall m in menuitems do
println m
od

!index:=finditem("menu->chicken->fried")
index:=finditem("menu->steak->strip->prices")

if index then
println "Found: ",menuitems[currindex]
while findnext() do
println "Next:",menuitems[currindex]
od

else
println "Not found"
fi
END

FUNCTION FINDITEM(searchstring)=
!return index of item (also in currindex), or 0 if not found

keywords:=splitstring(searchstring,"->")

!println "Keywords=",keywords
currindex:=0

forall i,k in keywords do !i is search level
do
++currindex
if currindex>menuitems.upb then return 0 fi
if menuitems[currindex].level<i then return 0 fi
if menuitems[currindex].name=k then exit fi !ie. break
od
od
return 1
END

FUNCTION FINDNEXT=
!return index of next item after currindex, at same level, otherwise return
0
if currindex=0 or currindex>=menuitems.upb then return 0 fi
currlevel:=menuitems[currindex].level
++currindex
if menuitems[currindex].level<currlevel then return 0 fi
return currindex
END

FUNCTION READMENU(file)=
f:=openfile(file)
if f=0 then return 0 fi

menuitems:=()
nitems:=0
currindex:=0

while not eof(f) do

readln #f,x:"l"
if x="" then loop fi

indent:=0
while left(x)="\t" do
++indent
x:=right(x,-1)
od
sreread()
read name:"n"
read value:"l"

menuitems[++nitems]:=rmenuitem(indent+1,name,value)
od

closefile(f)
return nitems
END
--
Bartc


Jun 27 '08 #5
* * *Then your problem seems to be more about algorithms than
about the language you implement them in.
--
Eric.Sos...@sun.com
You're right, now that you mention it.
Jun 27 '08 #6
Hello Doc, List

Sqlite can be one of your (best, IMHO) options.

http://www.sqlite.org/

Regards
Rafael
Jun 27 '08 #7
@Bartc,
Your comment about "how large can a restaurant menu be" is my thought
exactly. Just scanned your code and, if nothing else, it shows my
initial thoughts were along the same line and I have a little more
confidence in proceeding with my own code.

On Jun 24, 2:45*pm, soscpd <sos...@gmail.comwrote:
Hello Doc, List

Sqlite can be one of your (best, IMHO) options.

http://www.sqlite.org/

Regards
Rafael
I considered sqlite but for such a small amount of data, I just don't
feel this need to install any other programs.
Jun 27 '08 #8
On Tue, 24 Jun 2008 14:02:08 -0400,
Eric Sosman <Er*********@sun.comwrote:
Remember Douglas Adams' line
about a beverage "almost, but not quite exactly, unlike tea?"
Almost, but not quite, entirely unlike tea.

The placement of that comma makes a difference.

Martien
--
| Yes; Windows is great for running &
Martien Verbruggen | developing viruses, for instance. It's also
| very popular, but then again, so is the
| common cold. -- Dave Hinz
Jun 27 '08 #9
On Tue, 24 Jun 2008 13:14:33 -0700, drhowarddrfine wrote:
I considered sqlite but for such a small amount of data, I just don't
feel this need to install any other programs.
Actually, with the sqlite amalgamation you only need add two files to
your source tree (sqlite3.c and sqlite3.h). I use sqlite all the time and
can simply pass off binaries with sqlite included.
Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John | last post by:
Hi everyone ! This is a first time I post a message here. If I post my message in a wrong group. Please ignore it. I am trying to build a website which allows users (can be thousands of...
2
by: Dave Brueck | last post by:
Below is some information I collected from a *small* project in which I wrote a Python version of a Java application. I share this info only as a data point (rather than trying to say this data...
4
by: Michi | last post by:
I was wondering what the best solution is for making large numbers of TEXT (or BLOB?) fields searchable. For example, if I have a forum, what is the best way to be able to search for specific...
0
by: Mike | last post by:
Sites using thumbnail preview for world wide web file navigation and searching. Below are list of sites that are either researching or providing thumbnail preview images for online web...
13
by: Alan Silver | last post by:
Hello, MSDN (amongst other places) is full of helpful advice on ways to do data access, but they all seem geared to wards enterprise applications. Maybe I'm in a minority, but I don't have those...
4
by: Jordan S. | last post by:
Using .NET 2.0 (C#) I'm writing a small app that will have a "Person" class that exposes FirstName and LastName properties. At runtime, a "People" collection will be populated with a few thousand...
3
by: Gene Kelley | last post by:
Hello PHPers, I'm trying to get at a single line within a text file. For instance, I want to print the line within a the file named "file.txt" that starts with "17:". file.txt contains...
12
by: Alexnb | last post by:
This is similar to my last post, but a little different. Here is what I would like to do. Lets say I have a text file. The contents look like this, only there is A LOT of the same thing. () A...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.