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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:44:39+00:00 2026-05-12T08:44:39+00:00

I have recently read about how cursors should be avoided. Well, I would like

  • 0

I have recently read about how cursors should be avoided. Well, I would like to know if my usage of them is appropriate.

I am creating a scripting engine that will work online(embedded in a page, server-side) This scripting engine will be used by “advanced” end users of this product. The product works very heavily with the database however, and the scripting language is C-like, but simplified to where it also resembles PHP. For databases I basically want a syntax like this, as it is the most consistent syntax creatable within the language without the end user having to hand write SQL code(if we are going to make them do that, why can’t they just skip the scripting engine as its there to make life simpler). The syntax is something like this:

declare DataSet $data("tablename","OtherID="+$oid);
//Dataset(string tablename,string where_clause_addon)
$data["field1"]="the data of field... ";
$data.Next();  
$data["field1"]="The data of the next row";
$data[10]["field1"]="The data of the 10th row";

I control this internally by creating a global cursor for each DataSet (I only use 1 connection in the application) and then letting the global cursor keep track of the current row position(its a SCROLL and UPDATE cursor also). This makes my life much simpler as otherwise I would be forced to write my own SQL controls to combat .Net’s sucky DataReader.

Is this usage of cursors an OK one? Note that the page with these scripts will not be world wide accessible, its only for clients(so probably only like 3-10 users at once).

Does anyone see a better method of keeping track of the current variable location? (as these are able to address tables of unknown schema)

Also, would I have any problems with concurrency using cursors like this? (My docs say cursors are global to the connection, and each page request makes a new connection on the spot, so users aren’t sharing connections)

  • 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-12T08:44:39+00:00Added an answer on May 12, 2026 at 8:44 am

    “I have recently read about how cursors should be avoided.”

    They can’t be avoided.

    “I’ve read more that cursors shouldn’t necessarily be avoided, but rather that cursors are slow and should only be used in certain circumstances.”

    Correct — in certain situations.

    Use SQL statements to do as much as possible. Don’t invent your own SELECT processing logic by opening a cursor and doing a bunch of if-statements: use a WHERE clause. Don’t invent your own GROUP-BY processing by opening a cursor and reading each row: use a GROUP BY clause. Don’t invent your own join algorithm by using nested cursor loops: use a proper JOIN clause.

    Don’t invent your own SQL using cursors. Use SQL.

    Generally, the “don’t use cursors” folks are saying “Don’t reinvent SQL algorithms by using a cursor”. This is not a broad, vague “don’t use cursors”. It’s very specific advice: “Learn SQL, don’t work around gaps in your knowledge by writing cursor loops.”

    So long as you’re not reinventing an existing SQL algorithm, there are many things for which you must use cursors.

    Don’t fetishize over “avoiding cursors”. Do fetishize over doing as much in “pure SQL” as is reasonable.

    Don’t engage in premature optimization as you wring your hands over cursor/no-cursor programming. Simply write the best SQL you can and benchmark performance early and often.

    If you can’t figure out the best SQL, ask here for the best SQL — without fetishizing over cursors.

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

Sidebar

Related Questions

I have recently read about the 3 tier architecture, and i would like to
I have recently read topics about memory fragmentation: How to solve Memory Fragmentation and
I have read about the push technologies recently. Using it real-time data streaming is
Recently I have read a lot about different NoSQL databases and how they are
Recently I have read about hash-tables in a very famous book Introduction to Algorithms
I read recently about memory barriers and the reordering issue and now I have
I have recently read an article about fast sqrt calculation. Therefore, I have decided
I have recently read about XSLT and Xpath. But i came across document root
I have recently read about the Command Pattern This pattern is used to represent
A lot of what I have recently read about SMS uses a specification of

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.