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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:32:11+00:00 2026-05-27T06:32:11+00:00

@usersfound = User.find_by_sql([ SELECT * from users where name @@ plainto_tsquery(‘english’, ?) LIMIT 20

  • 0
@usersfound = User.find_by_sql(["

SELECT * from users where name @@ plainto_tsquery('english', ?) LIMIT 20 offset ?

  ",@query,@offset])

See above, is this safe from sql injection? I am very new to doing direct sql commands on a database in rails. (I am aware there may be other ways of doing this SPECIFIC query, but I am wondering if in general, using find_by_sql and that kind of insertion of vars is safe – I have some difficult queries with subselects and joins that are really possible to do with ActiveRecord.

Thanks.

  • 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-27T06:32:12+00:00Added an answer on May 27, 2026 at 6:32 am

    Yes, that should be safe. If you trace through the code you’ll find that your find_by_sql call ends up calling PGconn#send_query_prepared with the bind parameters being carried along as little more than baggage; the send_query_prepared method is just a wrapper for the PQsendQueryPrepared API call in libpq:

    static VALUE
    pgconn_send_query_prepared(int argc, VALUE *argv, VALUE self)
    {
        /* ... bunch of boiler plate marshalling stuff ... */
        result = PQsendQueryPrepared(conn, StringValuePtr(name), nParams, 
            (const char * const *)paramValues, paramLengths, paramFormats, 
            resultFormat);
        /* ... */
    }
    

    The bind parameters end up in paramValues. So you should be fine unless there are bugs in PostgreSQL’s C library prepared statement handling.

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

Sidebar

Related Questions

Here's the code: <?php mysqlLogin(); $username = $_COOKIE['username']; $sql = mysql_query(SELECT username FROM `users`
What I have right now is this: Dim users = From users In tempTable
In my ExtJS application I use EditorGridPanel to show data from server. var applicationsGrid
Loooking for a way to retrieve community from a large dataset I came across
I want to return data which belongs to only 1 user in a hasAndBelongsToMany
I have User object with a list of groups that it belongs to: public
Having received the following response from Foursquare, when I try to parse it, I
I used this hash function for a while (got it from the internet). The
I want to write a Console application which will just add a new User
I am using Django to receive and process push notifications from the foursquare real-time

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.