<commit_before>=============================================
How can I use data from other database tables
=============================================

You can use data from other database tables.

First you must specify table name and fields information.
You can do it the following way:

* Select project node in the task tree and click **Database** button.

* Set DB manual mode and specify the database connection attributes.

* Import tables information as described in the
  :doc:`Intergation with existing database </admin/intergation_with_existing_database>`
  
* Select project node in the task tree, click **Database** button restore previos values.

Then in the server module of the new items you must add code to read and write 
the data to the database

Below is the code for MySQL database (auto increameted primary field):

.. code-block:: py

  import MySQLdb
  from jam.db import mysql
  
  def on_open(item, params):
      connection = item.task.create_connection_ex(mysql, database='demo', \
          user='root', password='<PASSWORD>', host='localhost', encoding='UTF8')
      try:
          sql = item.get_select_query(params, mysql)
          rows = item.task.select(sql, connection, mysql)
      finally:
          connection.close()
      return rows, ''
  
  def on_apply(item, delta, params):
      connection = item.task.create_connection_ex(mysql, database='demo', \<commit_msg>Intergation increameted previos<commit_after>=============================================
How can I use data from other database tables
=============================================

You can use data from other database tables.

First you must specify table name and fields information.
You can do it the following way:

* Select project node in the task tree and click **Database** button.

* Set DB manual mode and specify the database connection attributes.

* Import tables information as described in the
  :doc:`Integration with existing database </admin/intergation_with_existing_database>`
  
* Select project node in the task tree, click **Database** button restore previous values.

Then in the server module of the new items you must add code to read and write 
the data to the database

Below is the code for MySQL database (auto incremented primary field):

.. code-block:: py

  import MySQLdb
  from jam.db import mysql
  
  def on_open(item, params):
      connection = item.task.create_connection_ex(mysql, database='demo', \
          user='root', password='<PASSWORD>', host='localhost', encoding='UTF8')
      try:
          sql = item.get_select_query(params, mysql)
          rows = item.task.select(sql, connection, mysql)
      finally:
          connection.close()
      return rows, ''
  
  def on_apply(item, delta, params):
      connection = item.task.create_connection_ex(mysql, database='demo', \
{'fraction_non_alphanumeric': 0.138174127599577, 'fraction_numerical': 0.0007049700387733521, 'mean_word_length': 4.005291005291006, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6198320', 'n_tokens_mistral': 721, 'n_tokens_neox': 705, 'n_words': 302}