Tag: mysql

Adding Columns (SQL Queries) to a CSV File in Ruby

I have been unable to figure out how to write additional columns, not rows, to a CSV file in Ruby. In this case, they are SQL queries. Snippet of my code: month = mysql.query(“SELECT DATE_FORMAT(company_db.dates.starting_date,’%m’) FROM company_db.dates.starting_date;”) day = mysql.query(“SELECT DATE_FORMAT(company_db.dates.starting_date,’%d’) FROM company_db.dates.starting_date;”) year = mysql.query(“SELECT DATE_FORMAT(company_db.dates.starting_date,’%Y’) FROM company_db.dates.starting_date;”) CSV.open(“Dates.csv, “wb”) do |csv| csv << […]

Can't Connect to MySQL server on '127.0.0.1'

I just installed the mysql2 gem for Windows 8 and had an extremely difficult time doing so. After I installed it, I still can’t run my Rails Application. System Information Operating System: Windows 8 Ruby Version: 2.0.0p481 (2014-05-08) [i386-mingw32] Gemfile gem ‘mysql2’, ‘0.3.17’ Database.yml development: adapter: mysql2 encoding: utf8 database: db_development pool: 5 username: root […]

Mysql format string when like compare

How could i tell mysql to compare my like condition, so that mysql before delete spaces from string and make symbols uppercase… For example, now my ruby code is such: LineItem.find(:all, :conditions => [“(description like ?) and (order_id in (?))”, “%#{params[:art_order_search]}%”, orders.map(&:id)]) But how can i do, that mysql field description (do not commit any […]

Rails app error – ActiveRecord::PendingMigrationError Migrations are pending; run 'rake db:migrate RAILS_ENV=development' to resolve this issue

The database is created, tables are created, data are there. But after I restarted the Rails application, I got this error. The app is using MySQL. What’s the issue here? Thank you in advance

Get max id of all sequences in PostgreSQL

We have a monitor on our databases to check for ids approaching max-int or max-bigint. We just moved from MySQL, and I’m struggling to get a similar check working on PostgreSQL. I’m hoping someone can help. Here’s the query in MySQL SELECT table_name, auto_increment FROM information_schema.tables WHERE table_schema = DATABASE(); I’m trying to get the […]

Saving a record.. but not saving… :(

I have this static method for a model, which is creating multiple records. This method is called when saving the parent, the data for creating appropriate n child records is passed to this method (new_record) which then iterates through the array passed to it, and creates the child records. Job has many Job Activities. This […]

Mac OS X Lion – mysql: command not found

I have installed MySQL from this source, installation was successfully finished. But when I run in terminal which mysql, the output is empty. When mysql, the output is -bash: mysql: command not found Also, I updated bundle and ran the app – the result: /Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/mysql2-0.3.11/lib/mysql2.rb:9:in `require’: Incorrect MySQL client library version! This gem was compiled […]

Ruby CSV read multiline fields

I exported tables and queries from SQL, where some of the fields are multi-line. The Ruby (1.9+) way to read CSV appears to be: require ‘csv’ CSV.foreach(“exported_mysql_table.csv”, {:headers=>true}) do |row| puts row end Which works great if my data is like this: “id”,”name”,”email”,”potato” 1,”Bob”,”bob@bob.bob”,”omnomnom” 2,”Charlie”,”char@char.com”,”andcheese” 4,”Doug”,”diggyd@diglet.com”,”usemeltattack” (The first line is the header/attributes) But if I […]

upon login authentication with LDAP/AD how do I create a user row if one is non existent using AD records

Currently I have this code for my sessions_controller: class SessionsController < ApplicationController def new end def create username = params[:nome] password = params[:password] name = username if AuthenticateUser.new(username, password).call user = User.create_with(nome: name).find_or_create_by(nome: user) session[:user_id] = user.id redirect_to ‘/’ else flash[:error] = “Erro! \nNĂºmero de Empregado e/ou password incorrecto(a)” redirect_to ‘/login’ end end def destroy […]

Ruby and MySQL UTF-8 characters

I’m switching a Sinatra application from SQLite3 to MySQL. For some reason, which I can’t understand, when I extract data from the MySQL using Ruby and Sequel the characters appear in 8-BIT ASCII instead of UTF-8. The deployment environment is a FreeBSD 9.1 and MySQL 5.6.12, with a system-wide ruby19 installed from FreeBSD ports. RVM […]

Ruby is the best programming language in the world - Ruby on Rails.