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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:48:51+00:00 2026-06-03T04:48:51+00:00

I have a list of sql queries beautifully encoded in utf-8. I read them

  • 0

I have a list of sql queries beautifully encoded in utf-8. I read them from files, perform the inserts and than do a select.

# encoding: utf-8 
def exec_sql_lines(file_name)
  puts "----> #{file_name} <----"
  File.open(file_name, 'r') do |f|
    # sometimes a query doesn't fit one line
    previous_line=""
    i = 0
    while line = f.gets do
      puts i+=1

      if(line[-2] != ')')
        previous_line += line[0..-2]
        next
      end

      puts (previous_line + line)  #  <----  (1)

      $db.execute((previous_line + line))
      previous_line =""
    end
    a = $db.execute("select * from Table where _id=6")
    puts a <---- (2)
  end
end

$db=SQLite3::Database.new($DBNAME)
exec_sql_lines("creates.txt")
exec_sql_lines("inserts.txt")
$db.close

The text in (1) is different than the one in (2). Polish letters get broken. If I use IRB and call $db.open ; $db.encoding is says UTF-8.

Why do Polish letters come out broken? How to fix it?

I need this database properly encoded in UTF-8 for my Android app, so I’m not interested in manipulating with database output. I need to fix it’s content.

EDIT

Significant lines from the output:

6
INSERT INTO 'Leki' VALUES (NULL, '6', 'Acenocoumarolum', 'Acenocumarol WZF', 'tabl. ', '4 mg', '60 tabl.', '5909990055715', '2012-01-01', '2 lata', '21.0, Leki przeciwzakrzepowe z grupy antagonistów witaminy K', '8.32', '12.07', '12.07', 'We wszystkich zarejestrowanych wskazaniach na dzień wydania decyzji', '', 'ryczałt', '5.12')

out:

6
6
Acenocoumarolum
Acenocumarol WZF
tabl. 
4 mg
60 tabl.
5909990055715
2012-01-01
2 lata
21.0, Leki przeciwzakrzepowe z grupy antagonistĂł[<--HERE]w witaminy K
8.32
12.07
12.07
We wszystkich zarejestrowanych wskazaniach na dzieĹ[<--HERE] wydania decyzji

ryczaĹ[<--HERE]t
5.12
  • 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-06-03T04:48:53+00:00Added an answer on June 3, 2026 at 4:48 am

    There are three default encoding.

    In you code you set the source encoding.
    Perhaps there is a problem with External and Internal Encoding?

    A quick test in windows:

    #encoding: utf-8
    File.open(__FILE__,'r'){|f|
      p f.external_encoding
      p f.internal_encoding
      p f.read.encoding
    }
    

    Result:

    #<Encoding:CP850>
    nil
    #<Encoding:CP850>
    

    Even if UTF-8 is used, the data are read as cp850.

    In your case:
    Does File.open(filename,'r:utf-8') help?

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

Sidebar

Related Questions

I have a set of sql - queries: List<String> queries = ... queries[0] =
I have a list of groups in a SQL query and would like them
I have a list of record Id's that I want to retrieve from Sql
I have an adjacency list of objects (rows loaded from SQL database with the
I have two SQL queries that I'm running from a C# winform, and I
How to loop through comma separated list in SQL? I have a list of
I have a list of objects which needs to be persisted in a SQL
I have a drop-down list which is generated based on the following sql query:
I have a SQL Server 2000 database that will not display the column list
I have a SharePoint external list that points to a 100,000 record SQL table.

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.