content stringlengths 7 1.05M | fixed_cases stringlengths 1 1.28M |
|---|---|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 2 18:04:28 2020
@author: boscolau
"""
class Buyer:
# Default constructor
def __init__(self, first_name: str, last_name: str, email: str):
"""
Initialize with specific values.
Parameters
----------
last_name : str
first_name : str
email : str
"""
self.last_name = last_name
self.first_name = first_name
self.email = email
def __str__(self):
return str(self.__dict__)
| """
Created on Thu Jul 2 18:04:28 2020
@author: boscolau
"""
class Buyer:
def __init__(self, first_name: str, last_name: str, email: str):
"""
Initialize with specific values.
Parameters
----------
last_name : str
first_name : str
email : str
"""
self.last_name = last_name
self.first_name = first_name
self.email = email
def __str__(self):
return str(self.__dict__) |
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name': 'Budgets Management',
'category': 'Accounting',
'description': """
This module allows accountants to manage analytic and crossovered budgets.
==========================================================================
Once the Budgets are defined (in Invoicing/Budgets/Budgets), the Project Managers
can set the planned amount on each Analytic Account.
The accountant has the possibility to see the total of amount planned for each
Budget in order to ensure the total planned is not greater/lower than what he
planned for this Budget. Each list of record can also be switched to a graphical
view of it.
Three reports are available:
----------------------------
1. The first is available from a list of Budgets. It gives the spreading, for
these Budgets, of the Analytic Accounts.
2. The second is a summary of the previous one, it only gives the spreading,
for the selected Budgets, of the Analytic Accounts.
3. The last one is available from the Analytic Chart of Accounts. It gives
the spreading, for the selected Analytic Accounts of Budgets.
""",
'website': 'https://www.odoo.com/page/accounting',
'depends': ['account'],
'data': [
'security/ir.model.access.csv',
'security/account_budget_security.xml',
'views/account_analytic_account_views.xml',
'views/account_budget_views.xml',
],
'demo': ['data/account_budget_demo.xml'],
}
| {'name': 'Budgets Management', 'category': 'Accounting', 'description': '\nThis module allows accountants to manage analytic and crossovered budgets.\n==========================================================================\n\nOnce the Budgets are defined (in Invoicing/Budgets/Budgets), the Project Managers\ncan set the planned amount on each Analytic Account.\n\nThe accountant has the possibility to see the total of amount planned for each\nBudget in order to ensure the total planned is not greater/lower than what he\nplanned for this Budget. Each list of record can also be switched to a graphical\nview of it.\n\nThree reports are available:\n----------------------------\n 1. The first is available from a list of Budgets. It gives the spreading, for\n these Budgets, of the Analytic Accounts.\n\n 2. The second is a summary of the previous one, it only gives the spreading,\n for the selected Budgets, of the Analytic Accounts.\n\n 3. The last one is available from the Analytic Chart of Accounts. It gives\n the spreading, for the selected Analytic Accounts of Budgets.\n', 'website': 'https://www.odoo.com/page/accounting', 'depends': ['account'], 'data': ['security/ir.model.access.csv', 'security/account_budget_security.xml', 'views/account_analytic_account_views.xml', 'views/account_budget_views.xml'], 'demo': ['data/account_budget_demo.xml']} |
# Write a program to take input marks of two subject and print aggregate.
S1=int(input("Enter 1st Marks:"))
S2=int(input("Enter 2nd Marks:"))
Total = S1 + S2;
Avg = Total/2;
print("Total marks = ", Total)
print("Average marks = ", Avg) | s1 = int(input('Enter 1st Marks:'))
s2 = int(input('Enter 2nd Marks:'))
total = S1 + S2
avg = Total / 2
print('Total marks = ', Total)
print('Average marks = ', Avg) |
# Take 2 of int, char or string, return the grater of 2
def greater(in_type, two_args):
if in_type == "int":
for i in range(len(two_args)):
two_args[i] = int(two_args[i])
elif in_type == "char":
for i in range(two_args):
two_args[i] = two_args[i][0]
two_args[i].title()
elif in_type == "string":
for i in range(two_args):
two_args[i].title()
else:
pass
result = two_args[0]
for i in range(two_args):
if two_args[i] >= result:
result = two_args[i]
result.title()
return(result)
input_type = input()
input_1 = input()
input_2 = input()
result = greater(input_type, [input_1, input_2])
print(result)
| def greater(in_type, two_args):
if in_type == 'int':
for i in range(len(two_args)):
two_args[i] = int(two_args[i])
elif in_type == 'char':
for i in range(two_args):
two_args[i] = two_args[i][0]
two_args[i].title()
elif in_type == 'string':
for i in range(two_args):
two_args[i].title()
else:
pass
result = two_args[0]
for i in range(two_args):
if two_args[i] >= result:
result = two_args[i]
result.title()
return result
input_type = input()
input_1 = input()
input_2 = input()
result = greater(input_type, [input_1, input_2])
print(result) |
class Result:
INDEX = 0
COLUMN = 1
DOCUMENT = 2
| class Result:
index = 0
column = 1
document = 2 |
def class_extensions():
def _additional_used_columns(self, parms):
"""
:return: Start and stop column if specified.
"""
result = []
for col in ["start_column", "stop_column"]:
if col in parms and parms[col] is not None:
result.append(parms[col])
return result
extensions = dict(
__class__=class_extensions,
)
doc = dict(
__class__="""
Trains a Cox Proportional Hazards Model (CoxPH) on an H2O dataset.
"""
)
| def class_extensions():
def _additional_used_columns(self, parms):
"""
:return: Start and stop column if specified.
"""
result = []
for col in ['start_column', 'stop_column']:
if col in parms and parms[col] is not None:
result.append(parms[col])
return result
extensions = dict(__class__=class_extensions)
doc = dict(__class__='\nTrains a Cox Proportional Hazards Model (CoxPH) on an H2O dataset.\n') |
def compute_acc(results):
labels = [pair[1] for pair in results]
predicts = [pair[2] for pair in results]
assert len(labels) == len(predicts)
acc = 0
for label, predict in zip(labels, predicts):
if label == predict:
acc += 1
return acc / len(labels) | def compute_acc(results):
labels = [pair[1] for pair in results]
predicts = [pair[2] for pair in results]
assert len(labels) == len(predicts)
acc = 0
for (label, predict) in zip(labels, predicts):
if label == predict:
acc += 1
return acc / len(labels) |
users = {
'juho': {
'name': 'Juho',
'username': 'juho',
'hashed_password': 'ei-selkokielinen-salasana',
'role': 'opettaja'
},
'olli': {
'name': 'Olli Opiskelija',
'username': 'olli',
'hashed_password': 'ei-selkokielinen-salasana',
'role': 'student'
}
}
| users = {'juho': {'name': 'Juho', 'username': 'juho', 'hashed_password': 'ei-selkokielinen-salasana', 'role': 'opettaja'}, 'olli': {'name': 'Olli Opiskelija', 'username': 'olli', 'hashed_password': 'ei-selkokielinen-salasana', 'role': 'student'}} |
# Remove Linear, annual, and semiannual trends
# Note: The keyword annual also removes semiannual trends
# To only remove semiannual but not annual trends,
# replace 'annual' with 'semiannual'
ap_tf_type = AutoList(['linear','annual'])
# Create Trend Filter to remove linear, annual, and semi-annual trend
fl_tf = skdiscovery.data_structure.series.filters.TrendFilter('TrendFilter', [ap_tf_type])
# Create stage container for the trend filter
sc_tf = StageContainer(fl_tf)
| ap_tf_type = auto_list(['linear', 'annual'])
fl_tf = skdiscovery.data_structure.series.filters.TrendFilter('TrendFilter', [ap_tf_type])
sc_tf = stage_container(fl_tf) |
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
"""
Functions to manipulate packed binary representations of number sets.
To save space, coverage stores sets of line numbers in SQLite using a packed
binary representation called a numbits. A numbits is a set of positive
integers.
A numbits is stored as a blob in the database. The exact meaning of the bytes
in the blobs should be considered an implementation detail that might change in
the future. Use these functions to work with those binary blobs of data.
"""
def nums_to_numbits(nums):
"""Convert `nums` into a numbits.
Arguments:
nums: a reusable iterable of integers, the line numbers to store.
Returns:
A binary blob.
"""
try:
nbytes = max(nums) // 8 + 1
except ValueError:
# nums was empty.
return b''
bb = bytearray(nbytes)
for num in nums:
bb[num//8] |= 1 << num % 8
return bytes(bb)
def numbits_to_nums(numbits):
"""Convert a numbits into a list of numbers.
Arguments:
numbits: a binary blob, the packed number set.
Returns:
A list of ints.
When registered as a SQLite function by :func:`register_sqlite_functions`,
this returns a string, a JSON-encoded list of ints.
"""
nums = []
for byte_i, byte in enumerate(numbits):
for bit_i in range(8):
if (byte & (1 << bit_i)):
nums.append(byte_i * 8 + bit_i)
return nums
| """
Functions to manipulate packed binary representations of number sets.
To save space, coverage stores sets of line numbers in SQLite using a packed
binary representation called a numbits. A numbits is a set of positive
integers.
A numbits is stored as a blob in the database. The exact meaning of the bytes
in the blobs should be considered an implementation detail that might change in
the future. Use these functions to work with those binary blobs of data.
"""
def nums_to_numbits(nums):
"""Convert `nums` into a numbits.
Arguments:
nums: a reusable iterable of integers, the line numbers to store.
Returns:
A binary blob.
"""
try:
nbytes = max(nums) // 8 + 1
except ValueError:
return b''
bb = bytearray(nbytes)
for num in nums:
bb[num // 8] |= 1 << num % 8
return bytes(bb)
def numbits_to_nums(numbits):
"""Convert a numbits into a list of numbers.
Arguments:
numbits: a binary blob, the packed number set.
Returns:
A list of ints.
When registered as a SQLite function by :func:`register_sqlite_functions`,
this returns a string, a JSON-encoded list of ints.
"""
nums = []
for (byte_i, byte) in enumerate(numbits):
for bit_i in range(8):
if byte & 1 << bit_i:
nums.append(byte_i * 8 + bit_i)
return nums |
class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
n = len(cost)
f = [None] * (n + 1)
f[0] = 0
f[1] = 0
for i in range(2, n + 1):
f[i] = min(f[i - 1] + cost[i - 1], f[i - 2] + cost[i - 2])
return f[n]
| class Solution:
def min_cost_climbing_stairs(self, cost: List[int]) -> int:
n = len(cost)
f = [None] * (n + 1)
f[0] = 0
f[1] = 0
for i in range(2, n + 1):
f[i] = min(f[i - 1] + cost[i - 1], f[i - 2] + cost[i - 2])
return f[n] |
#!/usr/bin/env python
# encoding: utf-8
"""
delete-node-in-a-linked-list.py
Created by Shuailong on 2016-02-04.
https://leetcode.com/problems/delete-node-in-a-linked-list/.
"""
# Definition for singly-linked list.
class ListNode(object):
def __init__(self, x):
self.val = x
self.next = None
class Solution(object):
def deleteNode(self, node):
"""
:type node: ListNode
:rtype: void Do not return anything, modify node in-place instead.
"""
node.val = node.next.val
node.next = node.next.next
def main():
pass
if __name__ == '__main__':
main()
| """
delete-node-in-a-linked-list.py
Created by Shuailong on 2016-02-04.
https://leetcode.com/problems/delete-node-in-a-linked-list/.
"""
class Listnode(object):
def __init__(self, x):
self.val = x
self.next = None
class Solution(object):
def delete_node(self, node):
"""
:type node: ListNode
:rtype: void Do not return anything, modify node in-place instead.
"""
node.val = node.next.val
node.next = node.next.next
def main():
pass
if __name__ == '__main__':
main() |
"""
dhtxmpp_component is a Python implementation of a DHT XMPP component.
"""
version_info = (0, 1)
version = '.'.join(map(str, version_info))
| """
dhtxmpp_component is a Python implementation of a DHT XMPP component.
"""
version_info = (0, 1)
version = '.'.join(map(str, version_info)) |
class mask:
"""
flatpak mask command
"""
def mask(self):
cmd = "flatpak mask {}".format(app.getAppId())
result=subprocess.run(cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode == 0:
return True
else:
return False
def unmask(self):
cmd = "flatpak mask --remove {}".format(app.getAppId())
result=subprocess.run(cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode == 0:
return True
else:
return False
def ismasked(self):
cmd = "flatpak mask"
result=subprocess.run(cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode == 0:
return True
else:
return False
| class Mask:
"""
flatpak mask command
"""
def mask(self):
cmd = 'flatpak mask {}'.format(app.getAppId())
result = subprocess.run(cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode == 0:
return True
else:
return False
def unmask(self):
cmd = 'flatpak mask --remove {}'.format(app.getAppId())
result = subprocess.run(cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode == 0:
return True
else:
return False
def ismasked(self):
cmd = 'flatpak mask'
result = subprocess.run(cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode == 0:
return True
else:
return False |
distances_from_sofia = [
('Bansko', 97),
('Brussels', 1701),
('Alexandria', 1403),
('Nice', 1307),
('Szeged', 469),
('Dublin', 2479),
('Palermo', 987),
('Oslo', 2098),
('Moscow', 1779),
('Madrid', 2259),
('London', 2019)
]
# variable to store the filtered list of distance tuples:
selected_distances = []
# filter each distance tuple:
for item in distances_from_sofia:
# each item is a tuple, and we check its second value:
if(item[1] < 1500):
selected_distances.append(item)
# print the filtered list of distance tuples:
print("Distances bellow 1500 km from Sofia are:")
for item in selected_distances:
print("{} - {}".format(item[0], item[1]))
| distances_from_sofia = [('Bansko', 97), ('Brussels', 1701), ('Alexandria', 1403), ('Nice', 1307), ('Szeged', 469), ('Dublin', 2479), ('Palermo', 987), ('Oslo', 2098), ('Moscow', 1779), ('Madrid', 2259), ('London', 2019)]
selected_distances = []
for item in distances_from_sofia:
if item[1] < 1500:
selected_distances.append(item)
print('Distances bellow 1500 km from Sofia are:')
for item in selected_distances:
print('{} - {}'.format(item[0], item[1])) |
class DocumentTagsMetadataMixin:
"""
Adds metadata support in form of tags on SSM document.
"""
def __init__(self, metadata=None, *args, **kwargs):
super().__init__(*args, **kwargs)
self.tags = metadata or []
def get_metadata(self):
return {**{tag.name: tag.value for tag in self.tags}, **super().get_metadata()}
| class Documenttagsmetadatamixin:
"""
Adds metadata support in form of tags on SSM document.
"""
def __init__(self, metadata=None, *args, **kwargs):
super().__init__(*args, **kwargs)
self.tags = metadata or []
def get_metadata(self):
return {**{tag.name: tag.value for tag in self.tags}, **super().get_metadata()} |
firstWord = input().lower()
secondWord = input().lower()
if firstWord == secondWord:
print("yes")
else:
print("no") | first_word = input().lower()
second_word = input().lower()
if firstWord == secondWord:
print('yes')
else:
print('no') |
class TreeNode:
def __init__(self, val, left=None, right=None):
self.val = val
self.left = left
self.right = right
def construct(inorder, level_order):
def helper(inorder):
if inorder is None:
return None
root = TreeNode(level_order.pop(0))
mid = inorder.index(root.val)
root.left = helper(inorder[:mid])
root.right = helper(inorder[mid+1:])
return root
helper(inorder)
def main():
root = TreeNode(20)
root.left = TreeNode(8)
root.right = TreeNode(22)
root.left.left = TreeNode(4)
root.left.right = TreeNode(12)
root.left.right.left = TreeNode(10)
root.left.right.right = TreeNode(4)
if __name__ == '__main__':
main()
| class Treenode:
def __init__(self, val, left=None, right=None):
self.val = val
self.left = left
self.right = right
def construct(inorder, level_order):
def helper(inorder):
if inorder is None:
return None
root = tree_node(level_order.pop(0))
mid = inorder.index(root.val)
root.left = helper(inorder[:mid])
root.right = helper(inorder[mid + 1:])
return root
helper(inorder)
def main():
root = tree_node(20)
root.left = tree_node(8)
root.right = tree_node(22)
root.left.left = tree_node(4)
root.left.right = tree_node(12)
root.left.right.left = tree_node(10)
root.left.right.right = tree_node(4)
if __name__ == '__main__':
main() |
android_desired_caps = {
"build": "Python Android",
'device': 'Google Pixel',
'os_version': '7.1',
'appPackage': 'com.auth0.samples',
'appActivity': 'com.auth0.samples.MainActivity',
'app': 'Auth0',
'chromeOptions': {
'androidPackage': 'com.android.chrome'
}
}
android_desired_caps_emulator = {
'platformName': 'android',
'deviceName': 'Nexus_6p',
'appPackage': 'com.auth0.samples',
'appActivity': 'com.auth0.samples.MainActivity',
'chromeOptions': {
'androidPackage': 'com.android.chrome'
}
}
ios_desired_caps = {
"platformName": "iOS",
"platformVersion": "11.0",
"deviceName": "iPhone 7",
"automationName": "XCUITest",
"app": "/path/to/my.app"
}
login_user = "asdasd"
login_password = "asdasd"
| android_desired_caps = {'build': 'Python Android', 'device': 'Google Pixel', 'os_version': '7.1', 'appPackage': 'com.auth0.samples', 'appActivity': 'com.auth0.samples.MainActivity', 'app': 'Auth0', 'chromeOptions': {'androidPackage': 'com.android.chrome'}}
android_desired_caps_emulator = {'platformName': 'android', 'deviceName': 'Nexus_6p', 'appPackage': 'com.auth0.samples', 'appActivity': 'com.auth0.samples.MainActivity', 'chromeOptions': {'androidPackage': 'com.android.chrome'}}
ios_desired_caps = {'platformName': 'iOS', 'platformVersion': '11.0', 'deviceName': 'iPhone 7', 'automationName': 'XCUITest', 'app': '/path/to/my.app'}
login_user = 'asdasd'
login_password = 'asdasd' |
""" Given the availability time slots arrays slots1 and slots2 of two people and
a meeting duration duration, return the earliest time slot that works for
both of them and is of duration duration.
If there is no common time slot that satisfies the requirements, return an
empty array.
The format of a time slot is an array of two elements [start, end]
representing an inclusive time range from start to end.
It is guaranteed that no two availability slots of the same person intersect
with each other. That is, for any two time slots [start1, end1] and [start2,
end2] of the same person, either start1 > end2 or start2 > end1.
Example 1:
Input: slots1 =
[[10,50],[60,120],[140,210]],
slots2 =
[[0,15],[60,70]],
duration = 8 Output: [60,68]
"""
class Solution1229:
pass
| """ Given the availability time slots arrays slots1 and slots2 of two people and
a meeting duration duration, return the earliest time slot that works for
both of them and is of duration duration.
If there is no common time slot that satisfies the requirements, return an
empty array.
The format of a time slot is an array of two elements [start, end]
representing an inclusive time range from start to end.
It is guaranteed that no two availability slots of the same person intersect
with each other. That is, for any two time slots [start1, end1] and [start2,
end2] of the same person, either start1 > end2 or start2 > end1.
Example 1:
Input: slots1 =
[[10,50],[60,120],[140,210]],
slots2 =
[[0,15],[60,70]],
duration = 8 Output: [60,68]
"""
class Solution1229:
pass |
class BaseConsumer(object):
"""
This class sets the blueprint for all the log event consumers
"""
@staticmethod
def process(log_line, log_group, log_stream):
pass
| class Baseconsumer(object):
"""
This class sets the blueprint for all the log event consumers
"""
@staticmethod
def process(log_line, log_group, log_stream):
pass |
def to_arabic(roman):
table = {"I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000}
n = len(roman)
number = 0
for i in range(n):
if i < n - 1 and table[roman[i]] < table[roman[i + 1]]:
number -= table[roman[i]]
else:
number += table[roman[i]]
return number
def to_roman(N):
table={1000:'M', 900:'CM', 500:'D', 400:'CD', 100:'C', 90:'XC', 50:'L', 40:'XL', 10:'X', 9:'IX', 5:'V', 4:'IV', 1:'I'}
roman = ""
for key in table.keys():
while N >= key:
roman += table[key]
N -= key
return roman
romans = ["CCCLXIX", "LXXX", "XXIX", "CLV", "XIV", "CDXCII", "CCCXLVIII", "CCCI", "CDLXIX", "CDXCIX"]
nums = [369, 80, 29, 155, 14, 492, 348, 301, 469, 499]
n = to_arabic(input())
m = to_arabic(input())
print(to_roman(n + m))
| def to_arabic(roman):
table = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
n = len(roman)
number = 0
for i in range(n):
if i < n - 1 and table[roman[i]] < table[roman[i + 1]]:
number -= table[roman[i]]
else:
number += table[roman[i]]
return number
def to_roman(N):
table = {1000: 'M', 900: 'CM', 500: 'D', 400: 'CD', 100: 'C', 90: 'XC', 50: 'L', 40: 'XL', 10: 'X', 9: 'IX', 5: 'V', 4: 'IV', 1: 'I'}
roman = ''
for key in table.keys():
while N >= key:
roman += table[key]
n -= key
return roman
romans = ['CCCLXIX', 'LXXX', 'XXIX', 'CLV', 'XIV', 'CDXCII', 'CCCXLVIII', 'CCCI', 'CDLXIX', 'CDXCIX']
nums = [369, 80, 29, 155, 14, 492, 348, 301, 469, 499]
n = to_arabic(input())
m = to_arabic(input())
print(to_roman(n + m)) |
n = int(input())
students_bellow_3 = 0
students_3_4 = 0
students_4_5 = 0
students_above_5 = 0
all_student_scores = 0
for i in range(1, n + 1):
student_score = float(input())
all_student_scores += student_score
if 2.00 <= student_score <= 2.99:
students_bellow_3 += 1
elif 3.00 <= student_score <= 3.99:
students_3_4 += 1
elif 4.00 <= student_score <= 4.99:
students_4_5 += 1
elif student_score >= 5.00:
students_above_5 += 1
students_above_5_perc = students_above_5 / n * 100
students_4_5_perc = students_4_5 / n * 100
students_3_4_perc = students_3_4 / n * 100
students_bellow_3_perc = students_bellow_3 / n * 100
average_score = all_student_scores / n
print(f"Top students: {students_above_5_perc:.2f}%")
print(f"Between 4.00 and 4.99: {students_4_5_perc:.2f}%")
print(f"Between 3.00 and 3.99: {students_3_4_perc:.2f}%")
print(f"Fail: {students_bellow_3_perc:.2f}%")
print(f"Average: {average_score:.2f}") | n = int(input())
students_bellow_3 = 0
students_3_4 = 0
students_4_5 = 0
students_above_5 = 0
all_student_scores = 0
for i in range(1, n + 1):
student_score = float(input())
all_student_scores += student_score
if 2.0 <= student_score <= 2.99:
students_bellow_3 += 1
elif 3.0 <= student_score <= 3.99:
students_3_4 += 1
elif 4.0 <= student_score <= 4.99:
students_4_5 += 1
elif student_score >= 5.0:
students_above_5 += 1
students_above_5_perc = students_above_5 / n * 100
students_4_5_perc = students_4_5 / n * 100
students_3_4_perc = students_3_4 / n * 100
students_bellow_3_perc = students_bellow_3 / n * 100
average_score = all_student_scores / n
print(f'Top students: {students_above_5_perc:.2f}%')
print(f'Between 4.00 and 4.99: {students_4_5_perc:.2f}%')
print(f'Between 3.00 and 3.99: {students_3_4_perc:.2f}%')
print(f'Fail: {students_bellow_3_perc:.2f}%')
print(f'Average: {average_score:.2f}') |
#Ingresar un numero de 4 digitos; Crea un algoritmo para sumar us digitos.
Numero=int(input("Ingresa el Valor: "))
D1=Numero//1000
r1=Numero%1000
D2=r1//100
r2=r1%100
D3=r2//10
D4=r2%10
Suma=D1+D2+D3+D4
print("El resultado es:",Suma)
print("orden: ",D1,D2,D3,D4)
print("reves",D4,D3,D2,D1)
| numero = int(input('Ingresa el Valor: '))
d1 = Numero // 1000
r1 = Numero % 1000
d2 = r1 // 100
r2 = r1 % 100
d3 = r2 // 10
d4 = r2 % 10
suma = D1 + D2 + D3 + D4
print('El resultado es:', Suma)
print('orden: ', D1, D2, D3, D4)
print('reves', D4, D3, D2, D1) |
fname = 'se.zone.txt'
names = set()
with open(fname, 'r') as f:
for line in f:
line = line.partition(';')[0].strip()
if len(line) == 0:
continue
domain, *_ = line.split()
domain = domain[:-1] # remove trailing dot
domain = domain.split('.')
if len(domain) == 1: # top level, ignore
continue
name = domain[-2]
names.add(name)
with open('se.names.txt', 'w') as f:
for name in sorted(names):
f.write(name + '\n')
| fname = 'se.zone.txt'
names = set()
with open(fname, 'r') as f:
for line in f:
line = line.partition(';')[0].strip()
if len(line) == 0:
continue
(domain, *_) = line.split()
domain = domain[:-1]
domain = domain.split('.')
if len(domain) == 1:
continue
name = domain[-2]
names.add(name)
with open('se.names.txt', 'w') as f:
for name in sorted(names):
f.write(name + '\n') |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class Hint():
def __init__(self, label, value):
self.label = label
self.value = value
def __repr__(self):
return '<Hint %r>' % self.label
def serialize(self):
return {
'label': self.label,
'value': self.value
}
| class Hint:
def __init__(self, label, value):
self.label = label
self.value = value
def __repr__(self):
return '<Hint %r>' % self.label
def serialize(self):
return {'label': self.label, 'value': self.value} |
"""
[API] Contains exceptions that may be exposed to the library client.
"""
class CachedMethodFailedException(Exception):
pass
| """
[API] Contains exceptions that may be exposed to the library client.
"""
class Cachedmethodfailedexception(Exception):
pass |
def pre_order(visitor, node):
visitor(node)
if node.l:
pre_order(visitor, node.l)
if node.r:
pre_order(visitor, node.r)
def in_order(visitor, node):
if node.l:
in_order(visitor, node.l)
visitor(node)
if node.r:
in_order(visitor, node.r)
def post_order(visitor, node):
if node.l:
post_order(visitor, node.l)
if node.r:
post_order(visitor, node.r)
visitor(node)
def visit(visitor, iter, order=pre_order):
for deriv in iter:
order(visitor, deriv.root)
yield deriv
def match(pattern, iter):
for deriv in iter:
res = pattern(deriv)
if res:
yield deriv, res
| def pre_order(visitor, node):
visitor(node)
if node.l:
pre_order(visitor, node.l)
if node.r:
pre_order(visitor, node.r)
def in_order(visitor, node):
if node.l:
in_order(visitor, node.l)
visitor(node)
if node.r:
in_order(visitor, node.r)
def post_order(visitor, node):
if node.l:
post_order(visitor, node.l)
if node.r:
post_order(visitor, node.r)
visitor(node)
def visit(visitor, iter, order=pre_order):
for deriv in iter:
order(visitor, deriv.root)
yield deriv
def match(pattern, iter):
for deriv in iter:
res = pattern(deriv)
if res:
yield (deriv, res) |
#Collect name from the user
name = input("What is your name? ")
#Display the name
print(name)
#Update the value
name = "Mary"
print(name)
#Create a friendly name
firstName = input("What is your first name? " )
lastName = input("What is your first name? " )
print("Hello " + firstName + " " + lastName) | name = input('What is your name? ')
print(name)
name = 'Mary'
print(name)
first_name = input('What is your first name? ')
last_name = input('What is your first name? ')
print('Hello ' + firstName + ' ' + lastName) |
def LeiaInt(msg):
valor = False
resultado = 0
while True:
n = (input(msg))
if n.isnumeric():
resultado = int(n)
valor = True
else:
print('ERROR: Digite novamente.')
if valor:
break
return resultado
# PROGRAMA
n = LeiaInt('Digite um numero: ')
print(f'O numero escolhido foi {n}') | def leia_int(msg):
valor = False
resultado = 0
while True:
n = input(msg)
if n.isnumeric():
resultado = int(n)
valor = True
else:
print('ERROR: Digite novamente.')
if valor:
break
return resultado
n = leia_int('Digite um numero: ')
print(f'O numero escolhido foi {n}') |
# This script converts a multiple sequence alignment into a matrix
# of pairwise sequence identities.
#
# Aleix Lafita - June 2018
# Input alignment and output identity matrix files
alignment_file = "PF06758_A0A87WZJ2.sto"
matrix_file = "PF06758_A0A87WZJ2_matrix.tsv"
with open(alignment_file, 'r') as input, open(matrix_file, 'w') as output:
# Load the alignment into a dictionary
alignment = {}
domains = []
# Read every line in the alignment file
for line in input:
# Check for comment lines or separators (Stockholm format)
if not line.startswith("#") and not line.startswith("//"):
row = line.split()
domain_id = row[0]
domains.append(domain_id)
if domain_id not in alignment.keys():
alignment[domain_id] = {}
alignment[domain_id] = row[1].strip("\n")
# Compute the sequence identity between all domain pairs
output.write("domain1\tdomain2\tpid\n")
# Double for loop for each domain pair
for i in range(0, len(domains)):
domain1 = domains[i]
for j in range(i + 1, len(domains)):
domain2 = domains[j]
length = 0
identicals = 0
# Just a check that the alignment is correct and residues are in position
assert len(alignment[domain1]) == len(alignment[domain2])
# Compare each position in the alignment
for x in range(0, len(alignment[domain1])):
# Check for gaps and aligned residues only
if (alignment[domain1][x] != '.'
and alignment[domain2][x] != '.'
and alignment[domain1][x] != '-'
and alignment[domain2][x] != '-'
and alignment[domain1][x].isupper()
and alignment[domain2][x].isupper()):
length += 1
if (alignment[domain1][x] == alignment[domain2][x]):
identicals += 1
# Compute the percentage of identity
pid = 1.0 * identicals / length
# Write the results into a tab separated format
output.write("{}\t{}\t{}\n".format(domain1, domain2, pid))
| alignment_file = 'PF06758_A0A87WZJ2.sto'
matrix_file = 'PF06758_A0A87WZJ2_matrix.tsv'
with open(alignment_file, 'r') as input, open(matrix_file, 'w') as output:
alignment = {}
domains = []
for line in input:
if not line.startswith('#') and (not line.startswith('//')):
row = line.split()
domain_id = row[0]
domains.append(domain_id)
if domain_id not in alignment.keys():
alignment[domain_id] = {}
alignment[domain_id] = row[1].strip('\n')
output.write('domain1\tdomain2\tpid\n')
for i in range(0, len(domains)):
domain1 = domains[i]
for j in range(i + 1, len(domains)):
domain2 = domains[j]
length = 0
identicals = 0
assert len(alignment[domain1]) == len(alignment[domain2])
for x in range(0, len(alignment[domain1])):
if alignment[domain1][x] != '.' and alignment[domain2][x] != '.' and (alignment[domain1][x] != '-') and (alignment[domain2][x] != '-') and alignment[domain1][x].isupper() and alignment[domain2][x].isupper():
length += 1
if alignment[domain1][x] == alignment[domain2][x]:
identicals += 1
pid = 1.0 * identicals / length
output.write('{}\t{}\t{}\n'.format(domain1, domain2, pid)) |
#email slicer program
email=[]
username=[]
mail_server=[]
top_level_domain=[]
n=int(input("ENTER THE NUMBER OF EMAILS : "))
print("\n")
for i in range(1,n+1):
name=input("PLEASE ENTER THE EMAIL ID : ").strip()
email.append(name)
for j in email:
a=j[:j.index('@')]
b=j[j.index('@')+1:j.index('.')]
c=j[j.index('.'):]
username.append(a)
mail_server.append(b)
top_level_domain.append(c)
for k in range(0,n):
print("\n{} .USERNAME : {}\n\nMAIL SERVER NAME : {}\n\nTOP LEVEL DOMAIN : {}".format(k+1,username[k],mail_server[k],top_level_domain[k]))
print("\n")
print("***************************************************************************")
| email = []
username = []
mail_server = []
top_level_domain = []
n = int(input('ENTER THE NUMBER OF EMAILS : '))
print('\n')
for i in range(1, n + 1):
name = input('PLEASE ENTER THE EMAIL ID : ').strip()
email.append(name)
for j in email:
a = j[:j.index('@')]
b = j[j.index('@') + 1:j.index('.')]
c = j[j.index('.'):]
username.append(a)
mail_server.append(b)
top_level_domain.append(c)
for k in range(0, n):
print('\n{} .USERNAME : {}\n\nMAIL SERVER NAME : {}\n\nTOP LEVEL DOMAIN : {}'.format(k + 1, username[k], mail_server[k], top_level_domain[k]))
print('\n')
print('***************************************************************************') |
list_of_inputs = open("./input.txt").readlines()
cleaned_list = []
for item in list_of_inputs:
cleaned_list.append(item.strip())
correct_passwords_count = 0
for item in cleaned_list:
chCorrect = 0
pCurrent = item.split(" ")
pInfo = pCurrent[0]
pTimesMin, pTimesMax = pInfo.split ("-")
pLetter = pCurrent[1].strip(":")
pCheckString = pCurrent[2].strip()
pCurrentLetterCount = pCheckString.count(pLetter)
if int(pTimesMin) <= int(pTimesMax) <= len(pCheckString):
if pCheckString[int(pTimesMin)-1] == pLetter:
chCorrect += 1
if pCheckString[int(pTimesMax)-1] == pLetter:
chCorrect += 1
if chCorrect == 1:
correct_passwords_count += 1
print(correct_passwords_count) | list_of_inputs = open('./input.txt').readlines()
cleaned_list = []
for item in list_of_inputs:
cleaned_list.append(item.strip())
correct_passwords_count = 0
for item in cleaned_list:
ch_correct = 0
p_current = item.split(' ')
p_info = pCurrent[0]
(p_times_min, p_times_max) = pInfo.split('-')
p_letter = pCurrent[1].strip(':')
p_check_string = pCurrent[2].strip()
p_current_letter_count = pCheckString.count(pLetter)
if int(pTimesMin) <= int(pTimesMax) <= len(pCheckString):
if pCheckString[int(pTimesMin) - 1] == pLetter:
ch_correct += 1
if pCheckString[int(pTimesMax) - 1] == pLetter:
ch_correct += 1
if chCorrect == 1:
correct_passwords_count += 1
print(correct_passwords_count) |
# Advent Of Code 2017, day 12, part 1
# http://adventofcode.com/2017/day/12
# solution by ByteCommander, 2017-12-12
with open("inputs/aoc2017_12.txt") as file:
links = {}
for line in file:
src, dests = line.split(" <-> ")
links[int(src)] = [int(dest) for dest in dests.split(", ")]
visited = set()
todo = {0}
while todo:
node = todo.pop()
visited.add(node)
for link in links[node]:
if link not in visited:
todo.add(link)
print("Answer: {} nodes are connected to node 0."
.format(len(visited)))
| with open('inputs/aoc2017_12.txt') as file:
links = {}
for line in file:
(src, dests) = line.split(' <-> ')
links[int(src)] = [int(dest) for dest in dests.split(', ')]
visited = set()
todo = {0}
while todo:
node = todo.pop()
visited.add(node)
for link in links[node]:
if link not in visited:
todo.add(link)
print('Answer: {} nodes are connected to node 0.'.format(len(visited))) |
stocks = {
'GOOG' : 434,
'AAPL' : 325,
'FB' : 54,
'AMZN' : 623,
'F' : 32,
'MSFT' : 549
}
print(min(zip(stocks.values(), stocks.keys()))) | stocks = {'GOOG': 434, 'AAPL': 325, 'FB': 54, 'AMZN': 623, 'F': 32, 'MSFT': 549}
print(min(zip(stocks.values(), stocks.keys()))) |
# Purpose: Define standard linetypes, text styles
# Created: 23.03.2016
# Copyright (C) 2016, Manfred Moitzi
# License: MIT License
def linetypes():
""" Creates a list of standard line types.
"""
# dxf linetype definition
# name, description, elements:
# elements = [total_pattern_length, elem1, elem2, ...]
# total_pattern_length = sum(abs(elem))
# elem > 0 is line, < 0 is gap, 0.0 = dot;
return [("CONTINUOUS", "Solid", [0.0]),
("CENTER", "Center ____ _ ____ _ ____ _ ____ _ ____ _ ____",
[2.0, 1.25, -0.25, 0.25, -0.25]),
("CENTERX2", "Center (2x) ________ __ ________ __ ________",
[3.5, 2.5, -0.25, 0.5, -0.25]),
("CENTER2", "Center (.5x) ____ _ ____ _ ____ _ ____ _ ____",
[1.0, 0.625, -0.125, 0.125, -0.125]),
("DASHED", "Dashed __ __ __ __ __ __ __ __ __ __ __ __ __ _",
[0.6, 0.5, -0.1]),
("DASHEDX2", "Dashed (2x) ____ ____ ____ ____ ____ ____",
[1.2, 1.0, -0.2]),
("DASHED2", "Dashed (.5x) _ _ _ _ _ _ _ _ _ _ _ _ _ _",
[0.3, 0.25, -0.05]),
("PHANTOM", "Phantom ______ __ __ ______ __ __ ______",
[2.5, 1.25, -0.25, 0.25, -0.25, 0.25, -0.25]),
("PHANTOMX2", "Phantom (2x)____________ ____ ____ ____________",
[4.25, 2.5, -0.25, 0.5, -0.25, 0.5, -0.25]),
("PHANTOM2", "Phantom (.5x) ___ _ _ ___ _ _ ___ _ _ ___ _ _ ___",
[1.25, 0.625, -0.125, 0.125, -0.125, 0.125, -0.125]),
("DASHDOT", "Dash dot __ . __ . __ . __ . __ . __ . __ . __",
[1.4, 1.0, -0.2, 0.0, -0.2]),
("DASHDOTX2", "Dash dot (2x) ____ . ____ . ____ . ____",
[2.4, 2.0, -0.2, 0.0, -0.2]),
("DASHDOT2", "Dash dot (.5x) _ . _ . _ . _ . _ . _ . _ . _",
[0.7, 0.5, -0.1, 0.0, -0.1]),
("DOT", "Dot . . . . . . . . . . . . . . . .",
[0.2, 0.0, -0.2]),
("DOTX2", "Dot (2x) . . . . . . . . ",
[0.4, 0.0, -0.4]),
("DOT2", "Dot (.5) . . . . . . . . . . . . . . . . . . . ",
[0.1, 0.0, -0.1]),
("DIVIDE", "Divide __ . . __ . . __ . . __ . . __ . . __",
[1.6, 1.0, -0.2, 0.0, -0.2, 0.0, -0.2]),
("DIVIDEX2", "Divide (2x) ____ . . ____ . . ____ . . ____",
[2.6, 2.0, -0.2, 0.0, -0.2, 0.0, -0.2]),
("DIVIDE2", "Divide(.5x) _ . _ . _ . _ . _ . _ . _ . _",
[0.8, 0.5, -0.1, 0.0, -0.1, 0.0, -0.1]),
]
def styles():
""" Creates a list of standard styles.
"""
return [
('STANDARD', 'arial.ttf'),
('ARIAL', 'arial.ttf'),
('ARIAL_NARROW', 'arialn.ttf'),
('ISOCPEUR', 'isocpeur.ttf'),
('TIMES', 'times.ttf'),
]
| def linetypes():
""" Creates a list of standard line types.
"""
return [('CONTINUOUS', 'Solid', [0.0]), ('CENTER', 'Center ____ _ ____ _ ____ _ ____ _ ____ _ ____', [2.0, 1.25, -0.25, 0.25, -0.25]), ('CENTERX2', 'Center (2x) ________ __ ________ __ ________', [3.5, 2.5, -0.25, 0.5, -0.25]), ('CENTER2', 'Center (.5x) ____ _ ____ _ ____ _ ____ _ ____', [1.0, 0.625, -0.125, 0.125, -0.125]), ('DASHED', 'Dashed __ __ __ __ __ __ __ __ __ __ __ __ __ _', [0.6, 0.5, -0.1]), ('DASHEDX2', 'Dashed (2x) ____ ____ ____ ____ ____ ____', [1.2, 1.0, -0.2]), ('DASHED2', 'Dashed (.5x) _ _ _ _ _ _ _ _ _ _ _ _ _ _', [0.3, 0.25, -0.05]), ('PHANTOM', 'Phantom ______ __ __ ______ __ __ ______', [2.5, 1.25, -0.25, 0.25, -0.25, 0.25, -0.25]), ('PHANTOMX2', 'Phantom (2x)____________ ____ ____ ____________', [4.25, 2.5, -0.25, 0.5, -0.25, 0.5, -0.25]), ('PHANTOM2', 'Phantom (.5x) ___ _ _ ___ _ _ ___ _ _ ___ _ _ ___', [1.25, 0.625, -0.125, 0.125, -0.125, 0.125, -0.125]), ('DASHDOT', 'Dash dot __ . __ . __ . __ . __ . __ . __ . __', [1.4, 1.0, -0.2, 0.0, -0.2]), ('DASHDOTX2', 'Dash dot (2x) ____ . ____ . ____ . ____', [2.4, 2.0, -0.2, 0.0, -0.2]), ('DASHDOT2', 'Dash dot (.5x) _ . _ . _ . _ . _ . _ . _ . _', [0.7, 0.5, -0.1, 0.0, -0.1]), ('DOT', 'Dot . . . . . . . . . . . . . . . .', [0.2, 0.0, -0.2]), ('DOTX2', 'Dot (2x) . . . . . . . . ', [0.4, 0.0, -0.4]), ('DOT2', 'Dot (.5) . . . . . . . . . . . . . . . . . . . ', [0.1, 0.0, -0.1]), ('DIVIDE', 'Divide __ . . __ . . __ . . __ . . __ . . __', [1.6, 1.0, -0.2, 0.0, -0.2, 0.0, -0.2]), ('DIVIDEX2', 'Divide (2x) ____ . . ____ . . ____ . . ____', [2.6, 2.0, -0.2, 0.0, -0.2, 0.0, -0.2]), ('DIVIDE2', 'Divide(.5x) _ . _ . _ . _ . _ . _ . _ . _', [0.8, 0.5, -0.1, 0.0, -0.1, 0.0, -0.1])]
def styles():
""" Creates a list of standard styles.
"""
return [('STANDARD', 'arial.ttf'), ('ARIAL', 'arial.ttf'), ('ARIAL_NARROW', 'arialn.ttf'), ('ISOCPEUR', 'isocpeur.ttf'), ('TIMES', 'times.ttf')] |
"""
The file defines the some Greek letters as pre-defined constants that have to be used
within the application. All letters are defined using the unicode encoding
"""
OMEGA_UNICODE = u"\u03C9"
MU_UNICODE = u"\u03BC"
NU_UNICODE = u"\u03B7"
XI_UNICODE = u"\u03BE"
KAPPA_UNICODE = u"\u03BA"
BETA_UNICODE = u"\u03B2"
SIGMA_UNICODE = u"\u03C3"
SUBSCRIPT_ONE = u"\u2081"
SUBSCRIPT_TWO = u"\u2082"
SUBSCRIPT_THREE = u"\u2083"
#-------------------------------------------------------------------------------
# User define variables
#-------------------------------------------------------------------------------
#.............................. ELASTIC MODULUS ..............................
EMODUL_X = "E" + SUBSCRIPT_ONE
EMODUL_Y = "E" + SUBSCRIPT_TWO
EMODUL_Z = "E" + SUBSCRIPT_THREE
EMODUL_XY = "G" + SUBSCRIPT_ONE + SUBSCRIPT_TWO
EMODUL_XZ = "G" + SUBSCRIPT_ONE + SUBSCRIPT_THREE
EMODUL_YZ = "G" + SUBSCRIPT_TWO + SUBSCRIPT_THREE
#.................................... NU ....................................
POISSON_RATIO_XY = NU_UNICODE + SUBSCRIPT_ONE + SUBSCRIPT_TWO
POISSON_RATIO_XZ = NU_UNICODE + SUBSCRIPT_ONE + SUBSCRIPT_THREE
POISSON_RATIO_YZ = NU_UNICODE + SUBSCRIPT_TWO + SUBSCRIPT_THREE
POISSON_RATIO_YX = NU_UNICODE + SUBSCRIPT_TWO + SUBSCRIPT_ONE
POISSON_RATIO_ZX = NU_UNICODE + SUBSCRIPT_THREE + SUBSCRIPT_ONE
POISSON_RATIO_ZY = NU_UNICODE + SUBSCRIPT_THREE + SUBSCRIPT_TWO
| """
The file defines the some Greek letters as pre-defined constants that have to be used
within the application. All letters are defined using the unicode encoding
"""
omega_unicode = u'ω'
mu_unicode = u'μ'
nu_unicode = u'η'
xi_unicode = u'ξ'
kappa_unicode = u'κ'
beta_unicode = u'β'
sigma_unicode = u'σ'
subscript_one = u'₁'
subscript_two = u'₂'
subscript_three = u'₃'
emodul_x = 'E' + SUBSCRIPT_ONE
emodul_y = 'E' + SUBSCRIPT_TWO
emodul_z = 'E' + SUBSCRIPT_THREE
emodul_xy = 'G' + SUBSCRIPT_ONE + SUBSCRIPT_TWO
emodul_xz = 'G' + SUBSCRIPT_ONE + SUBSCRIPT_THREE
emodul_yz = 'G' + SUBSCRIPT_TWO + SUBSCRIPT_THREE
poisson_ratio_xy = NU_UNICODE + SUBSCRIPT_ONE + SUBSCRIPT_TWO
poisson_ratio_xz = NU_UNICODE + SUBSCRIPT_ONE + SUBSCRIPT_THREE
poisson_ratio_yz = NU_UNICODE + SUBSCRIPT_TWO + SUBSCRIPT_THREE
poisson_ratio_yx = NU_UNICODE + SUBSCRIPT_TWO + SUBSCRIPT_ONE
poisson_ratio_zx = NU_UNICODE + SUBSCRIPT_THREE + SUBSCRIPT_ONE
poisson_ratio_zy = NU_UNICODE + SUBSCRIPT_THREE + SUBSCRIPT_TWO |
def format_positive_integer(number):
l = list(str(number))
c = len(l)
while c > 3:
c -= 3
l.insert(c, '.')
return ''.join(l)
def format_number(number, precision=0, group_sep='.', decimal_sep=','):
number = ('%.*f' % (max(0, precision), number)).split('.')
integer_part = number[0]
if integer_part[0] == '-':
sign = integer_part[0]
integer_part = integer_part[1:]
else:
sign = ''
if len(number) == 2:
decimal_part = decimal_sep + number[1]
else:
decimal_part = ''
integer_part = list(integer_part)
c = len(integer_part)
while c > 3:
c -= 3
integer_part.insert(c, group_sep)
return sign + ''.join(integer_part) + decimal_part
| def format_positive_integer(number):
l = list(str(number))
c = len(l)
while c > 3:
c -= 3
l.insert(c, '.')
return ''.join(l)
def format_number(number, precision=0, group_sep='.', decimal_sep=','):
number = ('%.*f' % (max(0, precision), number)).split('.')
integer_part = number[0]
if integer_part[0] == '-':
sign = integer_part[0]
integer_part = integer_part[1:]
else:
sign = ''
if len(number) == 2:
decimal_part = decimal_sep + number[1]
else:
decimal_part = ''
integer_part = list(integer_part)
c = len(integer_part)
while c > 3:
c -= 3
integer_part.insert(c, group_sep)
return sign + ''.join(integer_part) + decimal_part |
# MIT License
# #
# Copyright (c) 2022 by exersalza
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# #
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# for more information look at: https://aniapi.com/docs/pagination
PAGINATION = ['page',
'locale',
'per_page',
'ids',
'sort_fields',
'sort_directions']
ANIME_REQ = ['title',
'anilist_id',
'mal_id',
'tmdb_id',
'formats',
'status',
'year',
'season',
'genres',
'nsfw',
'with_episodes'] + PAGINATION
EPISODE_REQ = ['anime_id',
'number',
'is_dub',
'locale'] + PAGINATION
SONG_REQ = ['anime_id',
'title',
'artist',
'year',
'season',
'type'] + PAGINATION
USER_REQ = ['username',
'email'] + PAGINATION
UPDATE_USER_REQ = ['password',
'localization',
'anilist_id',
'anilist_token']
USER_STORY_REQ = ['anime_id',
'user_id',
'status',
'synced']
| pagination = ['page', 'locale', 'per_page', 'ids', 'sort_fields', 'sort_directions']
anime_req = ['title', 'anilist_id', 'mal_id', 'tmdb_id', 'formats', 'status', 'year', 'season', 'genres', 'nsfw', 'with_episodes'] + PAGINATION
episode_req = ['anime_id', 'number', 'is_dub', 'locale'] + PAGINATION
song_req = ['anime_id', 'title', 'artist', 'year', 'season', 'type'] + PAGINATION
user_req = ['username', 'email'] + PAGINATION
update_user_req = ['password', 'localization', 'anilist_id', 'anilist_token']
user_story_req = ['anime_id', 'user_id', 'status', 'synced'] |
#!/usr/bin/env python3
NUM_SOCKET = 2
NUM_PHYSICAL_CPU_PER_SOCKET = 12
SMT_LEVEL = 2
OS_CPU_ID = {} # socket_id, physical_cpu_id, smt_id
OS_CPU_ID[0,0,0] = 0
OS_CPU_ID[0,0,1] = 24
OS_CPU_ID[0,1,0] = 1
OS_CPU_ID[0,1,1] = 25
OS_CPU_ID[0,2,0] = 2
OS_CPU_ID[0,2,1] = 26
OS_CPU_ID[0,3,0] = 3
OS_CPU_ID[0,3,1] = 27
OS_CPU_ID[0,4,0] = 4
OS_CPU_ID[0,4,1] = 28
OS_CPU_ID[0,5,0] = 5
OS_CPU_ID[0,5,1] = 29
OS_CPU_ID[0,8,0] = 6
OS_CPU_ID[0,8,1] = 30
OS_CPU_ID[0,9,0] = 7
OS_CPU_ID[0,9,1] = 31
OS_CPU_ID[0,10,0] = 8
OS_CPU_ID[0,10,1] = 32
OS_CPU_ID[0,11,0] = 9
OS_CPU_ID[0,11,1] = 33
OS_CPU_ID[0,12,0] = 10
OS_CPU_ID[0,12,1] = 34
OS_CPU_ID[0,13,0] = 11
OS_CPU_ID[0,13,1] = 35
OS_CPU_ID[1,0,0] = 12
OS_CPU_ID[1,0,1] = 36
OS_CPU_ID[1,1,0] = 13
OS_CPU_ID[1,1,1] = 37
OS_CPU_ID[1,2,0] = 14
OS_CPU_ID[1,2,1] = 38
OS_CPU_ID[1,3,0] = 15
OS_CPU_ID[1,3,1] = 39
OS_CPU_ID[1,4,0] = 16
OS_CPU_ID[1,4,1] = 40
OS_CPU_ID[1,5,0] = 17
OS_CPU_ID[1,5,1] = 41
OS_CPU_ID[1,8,0] = 18
OS_CPU_ID[1,8,1] = 42
OS_CPU_ID[1,9,0] = 19
OS_CPU_ID[1,9,1] = 43
OS_CPU_ID[1,10,0] = 20
OS_CPU_ID[1,10,1] = 44
OS_CPU_ID[1,11,0] = 21
OS_CPU_ID[1,11,1] = 45
OS_CPU_ID[1,12,0] = 22
OS_CPU_ID[1,12,1] = 46
OS_CPU_ID[1,13,0] = 23
OS_CPU_ID[1,13,1] = 47
| num_socket = 2
num_physical_cpu_per_socket = 12
smt_level = 2
os_cpu_id = {}
OS_CPU_ID[0, 0, 0] = 0
OS_CPU_ID[0, 0, 1] = 24
OS_CPU_ID[0, 1, 0] = 1
OS_CPU_ID[0, 1, 1] = 25
OS_CPU_ID[0, 2, 0] = 2
OS_CPU_ID[0, 2, 1] = 26
OS_CPU_ID[0, 3, 0] = 3
OS_CPU_ID[0, 3, 1] = 27
OS_CPU_ID[0, 4, 0] = 4
OS_CPU_ID[0, 4, 1] = 28
OS_CPU_ID[0, 5, 0] = 5
OS_CPU_ID[0, 5, 1] = 29
OS_CPU_ID[0, 8, 0] = 6
OS_CPU_ID[0, 8, 1] = 30
OS_CPU_ID[0, 9, 0] = 7
OS_CPU_ID[0, 9, 1] = 31
OS_CPU_ID[0, 10, 0] = 8
OS_CPU_ID[0, 10, 1] = 32
OS_CPU_ID[0, 11, 0] = 9
OS_CPU_ID[0, 11, 1] = 33
OS_CPU_ID[0, 12, 0] = 10
OS_CPU_ID[0, 12, 1] = 34
OS_CPU_ID[0, 13, 0] = 11
OS_CPU_ID[0, 13, 1] = 35
OS_CPU_ID[1, 0, 0] = 12
OS_CPU_ID[1, 0, 1] = 36
OS_CPU_ID[1, 1, 0] = 13
OS_CPU_ID[1, 1, 1] = 37
OS_CPU_ID[1, 2, 0] = 14
OS_CPU_ID[1, 2, 1] = 38
OS_CPU_ID[1, 3, 0] = 15
OS_CPU_ID[1, 3, 1] = 39
OS_CPU_ID[1, 4, 0] = 16
OS_CPU_ID[1, 4, 1] = 40
OS_CPU_ID[1, 5, 0] = 17
OS_CPU_ID[1, 5, 1] = 41
OS_CPU_ID[1, 8, 0] = 18
OS_CPU_ID[1, 8, 1] = 42
OS_CPU_ID[1, 9, 0] = 19
OS_CPU_ID[1, 9, 1] = 43
OS_CPU_ID[1, 10, 0] = 20
OS_CPU_ID[1, 10, 1] = 44
OS_CPU_ID[1, 11, 0] = 21
OS_CPU_ID[1, 11, 1] = 45
OS_CPU_ID[1, 12, 0] = 22
OS_CPU_ID[1, 12, 1] = 46
OS_CPU_ID[1, 13, 0] = 23
OS_CPU_ID[1, 13, 1] = 47 |
# The first two are treated as literal blocks.
def example():
"""
This is a paragraph::
With a literal block.
While this one has trailing space::
So is this a literal block?
And this one has trailing chars:: !
- So this clearly isn't a literal block.
"""
return 1
| def example():
"""
This is a paragraph::
With a literal block.
While this one has trailing space::
So is this a literal block?
And this one has trailing chars:: !
- So this clearly isn't a literal block.
"""
return 1 |
'''
Created on Aug 13, 2018
@author: david avalos
'''
class Person:
def __init__(self, name):
self.name = name
def talk(self, words):
print(words)
def hobby(self):
print("My hobby is to watch movies")
class Teacher(Person):
def __init__(self, name, signature):
self.__name = name
self.__signature = signature
def hobby(self):
print("My hobby is to read")
def teach(self):
print(self.__name,"is giving",self.__signature,"class")
def getName(self):
return self.__name
def setName(self, name):
self.__name = name
class Engineer(Person):
def hobby(self):
print("My hobby is to play video games")
myPerson = Person("David")
myPerson.talk("Hello! :)")
myPerson.hobby()
print(myPerson.name)
print()
myTeacher = Teacher("Jorge","Math")
myTeacher.talk("Ready for my class?")
myTeacher.hobby()
myTeacher.teach()
#print(myTeacher.__name)
myTeacher.setName("Martin")
print(myTeacher.getName())
print()
myEngineer = Engineer("Genaro")
myEngineer.talk("Don't know what to say D:")
myEngineer.hobby()
print(myEngineer.name)
| """
Created on Aug 13, 2018
@author: david avalos
"""
class Person:
def __init__(self, name):
self.name = name
def talk(self, words):
print(words)
def hobby(self):
print('My hobby is to watch movies')
class Teacher(Person):
def __init__(self, name, signature):
self.__name = name
self.__signature = signature
def hobby(self):
print('My hobby is to read')
def teach(self):
print(self.__name, 'is giving', self.__signature, 'class')
def get_name(self):
return self.__name
def set_name(self, name):
self.__name = name
class Engineer(Person):
def hobby(self):
print('My hobby is to play video games')
my_person = person('David')
myPerson.talk('Hello! :)')
myPerson.hobby()
print(myPerson.name)
print()
my_teacher = teacher('Jorge', 'Math')
myTeacher.talk('Ready for my class?')
myTeacher.hobby()
myTeacher.teach()
myTeacher.setName('Martin')
print(myTeacher.getName())
print()
my_engineer = engineer('Genaro')
myEngineer.talk("Don't know what to say D:")
myEngineer.hobby()
print(myEngineer.name) |
# description: Generate PaseCliAsync_gen.c
# command: python gen.py
PaseSqlCli_file = "./gen_cli_template.c"
# ===============================================
# utilities
# ===============================================
def parse_sizeme( st ):
sz = '4'
if 'SMALL' in st:
sz = '2'
elif '*' in st:
sz = '4'
return sz
def parse_star( line ):
v1 = ""
v2 = ""
v3 = ""
# SQLRETURN * SQLFlinstone
# 0 1
split1 = line.split('*')
if len(split1) > 1:
v1 = split1[0]
v2 = "*"
v3 = split1[1]
else:
# SQLRETURN SQLRubble
# 0 1
split1 = line.split()
v1 = split1[0]
v2 = ""
v3 = split1[1]
return [v1.strip(),v2,v3.strip()]
def parse_method( line ):
# SQLRETURN SQLPrimaryKeys(...)
# ===func=================1
split1 = line.split("(")
func = split1[0]
# (SQLHSTMT hstmt, SQLCHAR * szTableQualifier, ...)
# 1================================argv========================2
split2 = split1[1].split(")")
argv = split2[0]
# SQLRETURN SQLRubble
# 0 1
# SQLRETURN * SQLFlinstone
# 0 1 2
funcs = parse_star(func)
# SQLHSTMT hstmt, SQLCHAR * szTableQualifier, ...
# 3 3
split3 = argv.split(",")
args = []
for arg in split3:
# SQLHSTMT hstmt
# 0 1
# SQLCHAR * szTableQualifier
# 0 1 2
args.append(parse_star(arg))
return [funcs,args]
# ===============================================
# special processing CLI interfaces (unique gen)
# ===============================================
# SQLRETURN SQLAllocEnv ( SQLHENV * phenv );
def PaseCliAsync_c_main_SQLAllocEnv(ile_or_custom_call, call_name, normal_db400_args):
c_main = ""
c_main += " int myccsid = init_CCSID400(0);" + "\n"
c_main += " init_lock();" + "\n"
c_main += " switch(myccsid) {" + "\n"
c_main += ' case 1208: /* UTF-8 */' + "\n"
c_main += ' case 1200: /* UTF-16 */' + "\n"
c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += " break;" + "\n"
c_main += ' default:' + "\n"
c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += " break;" + "\n"
c_main += " }" + "\n"
c_main += " if (sqlrc == SQL_SUCCESS) {" + "\n"
c_main += " init_table_ctor(*phenv, *phenv);" + "\n"
c_main += " custom_SQLSetEnvCCSID(*phenv, myccsid);" + "\n"
c_main += " }" + "\n"
c_main += " init_unlock();" + "\n"
# dump trace
c_main += " if (init_cli_trace()) {" + "\n"
c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n"
c_main += " }" + "\n"
return c_main
# SQLRETURN SQLAllocConnect ( SQLHENV henv, SQLHDBC * phdbc );
def PaseCliAsync_c_main_SQLAllocConnect(ile_or_custom_call, call_name, normal_db400_args):
c_main = ""
c_main += " int myccsid = init_CCSID400(0);" + "\n"
c_main += " init_lock();" + "\n"
c_main += " switch(myccsid) {" + "\n"
c_main += ' case 1208: /* UTF-8 */' + "\n"
c_main += ' case 1200: /* UTF-16 */' + "\n"
c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += " break;" + "\n"
c_main += ' default:' + "\n"
c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += " break;" + "\n"
c_main += " }" + "\n"
c_main += " if (sqlrc == SQL_SUCCESS) {" + "\n"
c_main += " init_table_ctor(*phdbc, *phdbc);" + "\n"
c_main += " }" + "\n"
c_main += " init_unlock();" + "\n"
# dump trace
c_main += " if (init_cli_trace()) {" + "\n"
c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n"
c_main += " }" + "\n"
return c_main
# SQLRETURN SQLAllocStmt ( SQLHDBC hdbc, SQLHSTMT * phstmt );
def PaseCliAsync_c_main_SQLAllocStmt(ile_or_custom_call, call_name, normal_db400_args):
c_main = ""
c_main += " int myccsid = init_CCSID400(0);" + "\n"
c_main += " init_lock();" + "\n"
c_main += " switch(myccsid) {" + "\n"
c_main += ' case 1208: /* UTF-8 */' + "\n"
c_main += ' case 1200: /* UTF-16 */' + "\n"
c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += " break;" + "\n"
c_main += ' default:' + "\n"
c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += " break;" + "\n"
c_main += " }" + "\n"
c_main += " if (sqlrc == SQL_SUCCESS) {" + "\n"
c_main += " init_table_ctor(*phstmt, hdbc);" + "\n"
c_main += " }" + "\n"
c_main += " init_unlock();" + "\n"
# dump trace
c_main += " if (init_cli_trace()) {" + "\n"
c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n"
c_main += " }" + "\n"
return c_main
# SQLRETURN SQLAllocHandle ( SQLSMALLINT htype, SQLINTEGER ihnd, SQLINTEGER * ohnd );
def PaseCliAsync_c_main_SQLAllocHandle(ile_or_custom_call, call_name, normal_db400_args):
c_main = ""
c_main += " int myccsid = init_CCSID400(0);" + "\n"
c_main += " init_lock();" + "\n"
c_main += " switch(myccsid) {" + "\n"
c_main += ' case 1208: /* UTF-8 */' + "\n"
c_main += ' case 1200: /* UTF-16 */' + "\n"
c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += " break;" + "\n"
c_main += ' default:' + "\n"
c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += " break;" + "\n"
c_main += " }" + "\n"
c_main += " switch (htype) {" + "\n"
c_main += " case SQL_HANDLE_ENV:" + "\n"
c_main += " if (sqlrc == SQL_SUCCESS) {" + "\n"
c_main += " init_table_ctor(*ohnd, *ohnd);" + "\n"
c_main += " custom_SQLSetEnvCCSID(*ohnd, myccsid);" + "\n"
c_main += " }" + "\n"
c_main += " break;" + "\n"
c_main += " case SQL_HANDLE_DBC:" + "\n"
c_main += " if (sqlrc == SQL_SUCCESS) {" + "\n"
c_main += " init_table_ctor(*ohnd, *ohnd);" + "\n"
c_main += " }" + "\n"
c_main += " break;" + "\n"
c_main += " case SQL_HANDLE_STMT:" + "\n"
c_main += " case SQL_HANDLE_DESC:" + "\n"
c_main += " if (sqlrc == SQL_SUCCESS) {" + "\n"
c_main += " init_table_ctor(*ohnd, ihnd);" + "\n"
c_main += " }" + "\n"
c_main += " break;" + "\n"
c_main += " }" + "\n"
c_main += " init_unlock();" + "\n"
# dump trace
c_main += " if (init_cli_trace()) {" + "\n"
c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n"
c_main += " }" + "\n"
return c_main
# SQLRETURN SQLFreeEnv ( SQLHENV henv );
def PaseCliAsync_c_main_SQLFreeEnv(ile_or_custom_call, call_name, normal_db400_args):
c_main = ""
c_main += " int myccsid = init_CCSID400(0);" + "\n"
c_main += " init_lock();" + "\n"
c_main += " switch(myccsid) {" + "\n"
c_main += ' case 1208: /* UTF-8 */' + "\n"
c_main += ' case 1200: /* UTF-16 */' + "\n"
c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += " break;" + "\n"
c_main += ' default:' + "\n"
c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += " break;" + "\n"
c_main += " }" + "\n"
c_main += " init_unlock();" + "\n"
# dump trace
c_main += " if (init_cli_trace()) {" + "\n"
c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n"
c_main += " }" + "\n"
return c_main
# SQLRETURN SQLFreeConnect ( SQLHDBC hdbc );
def PaseCliAsync_c_main_SQLFreeConnect(ile_or_custom_call, call_name, normal_db400_args):
c_main = ""
c_main += " int myccsid = init_CCSID400(0);" + "\n"
c_main += " int active = init_table_hash_active(hdbc, 0);" + "\n"
c_main += " /* persistent connect only close with SQL400pClose */" + "\n"
c_main += " if (active) {" + "\n"
c_main += " return SQL_ERROR;" + "\n"
c_main += " }" + "\n"
c_main += " init_lock();" + "\n"
c_main += " switch(myccsid) {" + "\n"
c_main += ' case 1208: /* UTF-8 */' + "\n"
c_main += ' case 1200: /* UTF-16 */' + "\n"
c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += " break;" + "\n"
c_main += ' default:' + "\n"
c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += " break;" + "\n"
c_main += " }" + "\n"
c_main += " init_table_dtor(hdbc);" + "\n"
c_main += " init_unlock();" + "\n"
# dump trace
c_main += " if (init_cli_trace()) {" + "\n"
c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n"
c_main += " }" + "\n"
return c_main
# SQLRETURN SQLFreeStmt ( SQLHSTMT hstmt, SQLSMALLINT fOption );
def PaseCliAsync_c_main_SQLFreeStmt(ile_or_custom_call, call_name, normal_db400_args):
c_main = ""
c_main += " int myccsid = init_CCSID400(0);" + "\n"
c_main += " init_lock();" + "\n"
c_main += " switch(myccsid) {" + "\n"
c_main += ' case 1208: /* UTF-8 */' + "\n"
c_main += ' case 1200: /* UTF-16 */' + "\n"
c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += " break;" + "\n"
c_main += ' default:' + "\n"
c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += " break;" + "\n"
c_main += " }" + "\n"
c_main += " init_table_dtor(hstmt);" + "\n"
c_main += " init_unlock();" + "\n"
# dump trace
c_main += " if (init_cli_trace()) {" + "\n"
c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n"
c_main += " }" + "\n"
return c_main
# SQLRETURN SQLFreeHandle ( SQLSMALLINT htype, SQLINTEGER hndl );
def PaseCliAsync_c_main_SQLFreeHandle(ile_or_custom_call, call_name, normal_db400_args):
c_main = ""
c_main += " int myccsid = init_CCSID400(0);" + "\n"
c_main += " int persistent = init_table_hash_active(hndl, 0);" + "\n"
c_main += " /* persistent connect only close with SQL400pClose */" + "\n"
c_main += " switch (htype) {" + "\n"
c_main += " case SQL_HANDLE_DBC:" + "\n"
c_main += " if (persistent) {" + "\n"
c_main += " return SQL_ERROR;" + "\n"
c_main += " }" + "\n"
c_main += " break;" + "\n"
c_main += ' default:' + "\n"
c_main += " break;" + "\n"
c_main += " }" + "\n"
c_main += " init_lock();" + "\n"
c_main += " switch(myccsid) {" + "\n"
c_main += ' case 1208: /* UTF-8 */' + "\n"
c_main += ' case 1200: /* UTF-16 */' + "\n"
c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += " break;" + "\n"
c_main += ' default:' + "\n"
c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += " break;" + "\n"
c_main += " }" + "\n"
c_main += " switch (htype) {" + "\n"
c_main += " case SQL_HANDLE_ENV:" + "\n"
c_main += " break;" + "\n"
c_main += " default:" + "\n"
c_main += " init_table_dtor(hndl);" + "\n"
c_main += " break;" + "\n"
c_main += " }" + "\n"
c_main += " init_unlock();" + "\n"
# dump trace
c_main += " if (init_cli_trace()) {" + "\n"
c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n"
c_main += " }" + "\n"
return c_main
# SQLRETURN SQLDisconnect( SQLHDBC hdbc )
def SQLDisconnect_check_persistent(hdbc_code, return_code, set_code):
c_main = ""
c_main += " int persistent = init_table_hash_active(" + hdbc_code + ", 0);" + "\n"
c_main += " /* persistent connect only close with SQL400pClose */" + "\n"
c_main += " if (persistent) {" + "\n"
c_main += " " + set_code + "\n"
c_main += " " + return_code + "\n"
c_main += " }" + "\n"
return c_main
# ===============================================
# non-utf (old libdb400.a)
# ===============================================
# SQL400IgnoreNullAnyToAny(hdbc, inparm, inlen, outparm, outlen, inccsid, outccsid)
# SQL400IgnoreNullAnyFromAny(hdbc, inparm, inlen, outparm, outlen, inccsid, outccsid)
def non_utf_copy_in():
c_main = ""
c_main += 'int non_utf_copy_in_hdbc(SQLHDBC hdbc, SQLCHAR **tmp, SQLCHAR **src, SQLINTEGER srclen, SQLINTEGER maxlen) {' + "\n"
c_main += ' SQLRETURN sqlrc1 = SQL_SUCCESS;' + "\n"
c_main += ' int inccsid = init_CCSID400(0);' + "\n"
c_main += ' int outccsid = init_job_CCSID400();' + "\n"
c_main += ' SQLCHAR * inparm = *src;' + "\n"
c_main += ' SQLINTEGER inlen = srclen;' + "\n"
c_main += ' SQLCHAR * outparm = (SQLCHAR *) NULL;' + "\n"
c_main += ' SQLINTEGER outlen = 0;' + "\n"
c_main += ' if (inparm) {' + "\n"
c_main += ' if (srclen == SQL_NTS) {' + "\n"
c_main += ' inlen = strlen(inparm);' + "\n"
c_main += ' }' + "\n"
c_main += ' outlen = maxlen;' + "\n"
c_main += ' outparm = (SQLCHAR *) malloc(outlen);' + "\n"
c_main += ' memset(outparm,0,outlen);' + "\n"
c_main += ' sqlrc1 = SQL400IgnoreNullAnyToAny(hdbc, inparm, inlen, outparm, outlen, inccsid, outccsid);' + "\n"
c_main += ' outlen = strlen(outparm);' + "\n"
c_main += ' }' + "\n"
c_main += ' *tmp = *src;' + "\n"
c_main += ' if (*src) {' + "\n"
c_main += ' *src = outparm;' + "\n"
c_main += ' }' + "\n"
c_main += ' return outlen;' + "\n"
c_main += '}' + "\n"
c_main += 'int non_utf_copy_in_hstmt(SQLHSTMT hstmt, SQLCHAR **tmp, SQLCHAR **src, SQLINTEGER srclen, SQLINTEGER maxlen) {' + "\n"
c_main += ' SQLHDBC hdbc = init_table_stmt_2_conn(hstmt);' + "\n"
c_main += ' return non_utf_copy_in_hdbc(hdbc, tmp, src, srclen, maxlen);' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_copy_in_free():
c_main = ""
c_main += 'void non_utf_copy_in_free(SQLCHAR **tmp, SQLCHAR **src) {' + "\n"
c_main += ' char * trash = *src;' + "\n"
c_main += ' *src = *tmp;' + "\n"
c_main += ' if (trash) {' + "\n"
c_main += ' free(trash);' + "\n"
c_main += ' *tmp = NULL;' + "\n"
c_main += ' }' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_copy_out():
c_main = ""
c_main += 'int non_utf_copy_out_hdbc(SQLHDBC hdbc, SQLRETURN sqlrc, SQLCHAR *src, SQLINTEGER srclen) {' + "\n"
c_main += ' SQLRETURN sqlrc1 = SQL_SUCCESS;' + "\n"
c_main += ' int inccsid = init_CCSID400(0);' + "\n"
c_main += ' int outccsid = init_job_CCSID400();' + "\n"
c_main += ' SQLCHAR * inparm = src;' + "\n"
c_main += ' SQLINTEGER inlen = srclen;' + "\n"
c_main += ' SQLCHAR * outparm = (SQLCHAR *) NULL;' + "\n"
c_main += ' SQLINTEGER outlen = 0;' + "\n"
c_main += ' if (inparm && (inlen != SQL_NULL_DATA) && (sqlrc == SQL_SUCCESS || sqlrc == SQL_SUCCESS_WITH_INFO)) {' + "\n"
c_main += ' outlen = inlen + 1;' + "\n"
c_main += ' outparm = (SQLCHAR *) malloc(outlen);' + "\n"
c_main += ' memset(outparm,0,outlen);' + "\n"
c_main += ' sqlrc1 = SQL400IgnoreNullAnyFromAny(hdbc, inparm, inlen, outparm, outlen, inccsid, outccsid);' + "\n"
c_main += ' outlen = strlen(outparm);' + "\n"
c_main += ' memcpy(inparm,outparm,inlen);' + "\n"
c_main += ' free(outparm);' + "\n"
c_main += ' }' + "\n"
c_main += ' return outlen;' + "\n"
c_main += '}' + "\n"
c_main += 'int non_utf_copy_out_hstmt(SQLHSTMT hstmt, SQLRETURN sqlrc, SQLCHAR *src, SQLINTEGER srclen) {' + "\n"
c_main += ' SQLHDBC hdbc = init_table_stmt_2_conn(hstmt);' + "\n"
c_main += ' return non_utf_copy_out_hdbc(hdbc, sqlrc, src, srclen);' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_isconvert_ordinal():
c_main = ""
c_main += 'int non_utf_isconvert_ordinal(SQLINTEGER ord) {' + "\n"
c_main += ' int convert = 0;' + "\n"
c_main += ' switch(ord) {' + "\n"
c_main += ' case SQL_ATTR_DBC_DEFAULT_LIB:' + " \n"
c_main += ' case SQL_ATTR_SAVEPOINT_NAME:' + " \n"
c_main += ' case SQL_ATTR_INFO_ACCTSTR:' + " \n"
c_main += ' case SQL_ATTR_INFO_APPLNAME:' + " \n"
c_main += ' case SQL_ATTR_INFO_PROGRAMID:' + " \n"
c_main += ' case SQL_ATTR_INFO_USERID:' + " \n"
c_main += ' case SQL_ATTR_INFO_WRKSTNNAME:' + " \n"
c_main += ' case SQL_ATTR_SERVERMODE_SUBSYSTEM:' + " \n"
c_main += ' case SQL_DBMS_NAME:' + " \n"
c_main += ' case SQL_DBMS_VER:' + " \n"
c_main += ' case SQL_PROCEDURES:' + " \n"
c_main += ' case SQL_DATA_SOURCE_NAME:' + " \n"
c_main += ' case SQL_COLUMN_ALIAS:' + " \n"
c_main += ' case SQL_DATA_SOURCE_READ_ONLY:' + " \n"
c_main += ' case SQL_MULTIPLE_ACTIVE_TXN:' + " \n"
c_main += ' case SQL_DRIVER_NAME:' + " \n"
c_main += ' case SQL_IDENTIFIER_QUOTE_CHAR:' + " \n"
c_main += ' case SQL_PROCEDURE_TERM:' + " \n"
c_main += ' case SQL_QUALIFIER_TERM:' + " \n"
c_main += ' case SQL_QUALIFIER_NAME_SEPARATOR:' + " \n"
c_main += ' case SQL_OWNER_TERM:' + " \n"
c_main += ' case SQL_DRIVER_ODBC_VER:' + " \n"
c_main += ' case SQL_ORDER_BY_COLUMNS_IN_SELECT:' + " \n"
c_main += ' case SQL_SEARCH_PATTERN_ESCAPE:' + " \n"
c_main += ' case SQL_OUTER_JOINS:' + " \n"
c_main += ' case SQL_LIKE_ESCAPE_CLAUSE:' + " \n"
c_main += ' case SQL_CATALOG_NAME:' + " \n"
c_main += ' case SQL_DESCRIBE_PARAMETER:' + " \n"
c_main += ' convert = 1;' + "\n"
c_main += ' break;' + "\n"
c_main += ' }' + "\n"
c_main += ' return convert;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLColAttributes(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER outsz = 0;' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' if (fDescType == SQL_DESC_NAME) {' + "\n"
c_main += ' outsz = non_utf_copy_out_hstmt(hstmt, sqlrc, (SQLCHAR *)rgbDesc, (SQLINTEGER)cbDescMax);' + "\n"
c_main += ' if (pcbDesc) *pcbDesc = outsz;' + "\n"
c_main += ' }' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLColumnPrivileges(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n"
c_main += ' SQLCHAR * tmp1 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp2 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp3 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp4 = NULL;' + "\n"
c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)cbTableQualifier, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)cbTableOwner, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)cbTableName, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbColumnName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName, (SQLINTEGER)cbColumnName, (SQLINTEGER)maxsz);' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName);' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLColumns(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n"
c_main += ' SQLCHAR * tmp1 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp2 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp3 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp4 = NULL;' + "\n"
c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)cbTableQualifier, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)cbTableOwner, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)cbTableName, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbColumnName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName, (SQLINTEGER)cbColumnName, (SQLINTEGER)maxsz);' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName);' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLConnect(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n"
c_main += ' SQLCHAR * tmp1 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp2 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp3 = NULL;' + "\n"
c_main += ' cbDSN = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp1, (SQLCHAR **)&szDSN, (SQLINTEGER)cbDSN, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbUID = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp2, (SQLCHAR **)&szUID, (SQLINTEGER)cbUID, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbAuthStr = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp3, (SQLCHAR **)&szAuthStr, (SQLINTEGER)cbAuthStr, (SQLINTEGER)maxsz);' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szDSN);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szUID);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szAuthStr);' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLDataSources(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER tmpsz = 0;' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' tmpsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szDSN, (SQLINTEGER)cbDSNMax);' + "\n"
c_main += ' tmpsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szDescription, (SQLINTEGER)cbDescriptionMax);' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLDescribeCol(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER outsz = 0;' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szColName, (SQLINTEGER)cbColNameMax);' + "\n"
c_main += ' if (pcbColName) *pcbColName = outsz;' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLDriverConnect(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER outsz = 0;' + "\n"
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n"
c_main += ' SQLCHAR * tmp1 = NULL;' + "\n"
c_main += ' cbConnStrin = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp1, (SQLCHAR **)&szConnStrIn, (SQLINTEGER)cbConnStrin, (SQLINTEGER)maxsz);' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szConnStrIn);' + "\n"
c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szConnStrOut, (SQLINTEGER)cbConnStrOutMax);' + "\n"
c_main += ' if (pcbConnStrOut) *pcbConnStrOut = outsz;' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLError(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER outsz = 0;' + "\n"
c_main += ' SQLINTEGER maxsz = SQL_SQLSTATE_SIZE + 1;' + "\n"
c_main += ' SQLINTEGER tmpsz = 0;' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' tmpsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szSqlState, (SQLINTEGER)maxsz);' + "\n"
c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szErrorMsg, (SQLINTEGER)cbErrorMsgMax);' + "\n"
c_main += ' if (pcbErrorMsg) *pcbErrorMsg = outsz;' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLExecDirect(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + "\n"
c_main += ' SQLCHAR * tmp1 = NULL;' + "\n"
c_main += ' cbSqlStr = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStr, (SQLINTEGER)cbSqlStr, (SQLINTEGER)maxsz);' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStr);' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLForeignKeys(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n"
c_main += ' SQLCHAR * tmp1 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp2 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp3 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp4 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp5 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp6 = NULL;' + "\n"
c_main += ' cbPkTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szPkTableQualifier, (SQLINTEGER)cbPkTableQualifier, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbPkTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szPkTableOwner, (SQLINTEGER)cbPkTableOwner, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbPkTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szPkTableName, (SQLINTEGER)cbPkTableName, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbFkTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp4, (SQLCHAR **)&szFkTableQualifier, (SQLINTEGER)cbFkTableQualifier, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbFkTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp5, (SQLCHAR **)&szFkTableOwner, (SQLINTEGER)cbFkTableOwner, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbFkTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp6, (SQLCHAR **)&szFkTableName, (SQLINTEGER)cbFkTableName, (SQLINTEGER)maxsz);' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szPkTableQualifier);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szPkTableOwner);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szPkTableName);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp4, (SQLCHAR **)&szFkTableQualifier);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp5, (SQLCHAR **)&szFkTableOwner);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp6, (SQLCHAR **)&szFkTableName);' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLGetConnectAttr(call_name, normal_db400_args):
c_main = ""
c_main += ' int isconvert = non_utf_isconvert_ordinal(attr);' + "\n"
c_main += ' SQLINTEGER outsz = 0;' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' if (isconvert) {' + "\n"
c_main += ' outsz = non_utf_copy_out_hdbc(hdbc, sqlrc, (SQLCHAR *)oval, (SQLINTEGER)ilen);' + "\n"
c_main += ' if (olen) *olen = outsz;' + "\n"
c_main += ' }' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLGetConnectOption(call_name, normal_db400_args):
c_main = ""
c_main += ' int isconvert = non_utf_isconvert_ordinal(iopt);' + "\n"
c_main += ' SQLINTEGER maxsz = DFTCOLSIZE;' + "\n"
c_main += ' SQLINTEGER tmpsz = 0;' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' if (isconvert) {' + "\n"
c_main += ' tmpsz = non_utf_copy_out_hdbc(hdbc, sqlrc, (SQLCHAR *)oval, (SQLINTEGER)maxsz);' + "\n"
c_main += ' }' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLGetCursorName(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER outsz = 0;' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szCursor, (SQLINTEGER)cbCursorMax);' + "\n"
c_main += ' if (pcbCursor) *pcbCursor = outsz;' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLGetDescField(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER outsz = 0;' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' if (fieldID == SQL_DESC_NAME) {' + "\n"
c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)fValue, (SQLINTEGER)fLength);' + "\n"
c_main += ' if (stLength) *stLength = outsz;' + "\n"
c_main += ' }' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLGetDescRec(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER outsz = 0;' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)fname, (SQLINTEGER)bufLen);' + "\n"
c_main += ' if (sLength) *sLength = outsz;' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLGetDiagField(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER outsz = 0;' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' if (diagID == SQL_DIAG_SQLSTATE || diagID == SQL_DIAG_MESSAGE_TEXT || diagID == SQL_DIAG_SERVER_NAME) {' + "\n"
c_main += ' if (hType == SQL_HANDLE_DBC) {' + "\n"
c_main += ' outsz = non_utf_copy_out_hdbc(hndl, sqlrc, (SQLCHAR *)dValue, (SQLINTEGER)bLength);' + "\n"
c_main += ' } else {' + "\n"
c_main += ' outsz = non_utf_copy_out_hstmt(hndl, sqlrc, (SQLCHAR *)dValue, (SQLINTEGER)bLength);' + "\n"
c_main += ' }' + "\n"
c_main += ' if (sLength) *sLength = outsz;' + "\n"
c_main += ' }' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLGetDiagRec(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER outsz = 0;' + "\n"
c_main += ' SQLINTEGER maxsz = SQL_SQLSTATE_SIZE + 1;' + "\n"
c_main += ' SQLINTEGER tmpsz = 0;' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' if (hType == SQL_HANDLE_DBC) {' + "\n"
c_main += ' tmpsz = non_utf_copy_out_hdbc(hndl, sqlrc, (SQLCHAR *)SQLstate, (SQLINTEGER)maxsz);' + "\n"
c_main += ' outsz = non_utf_copy_out_hdbc(hndl, sqlrc, (SQLCHAR *)msgText, (SQLINTEGER)bLength);' + "\n"
c_main += ' } else {' + "\n"
c_main += ' tmpsz = non_utf_copy_out_hstmt(hndl, sqlrc, (SQLCHAR *)SQLstate, (SQLINTEGER)maxsz);' + "\n"
c_main += ' outsz = non_utf_copy_out_hstmt(hndl, sqlrc, (SQLCHAR *)msgText, (SQLINTEGER)bLength);' + "\n"
c_main += ' }' + "\n"
c_main += ' if (SLength) *SLength = outsz;' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLGetEnvAttr(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER outsz = 0;' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' if (fAttribute == SQL_ATTR_DEFAULT_LIB || fAttribute == SQL_ATTR_ESCAPE_CHAR) {' + "\n"
c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)pParam, (SQLINTEGER)cbParamMax);' + "\n"
c_main += ' }' + "\n"
c_main += ' if (pcbParam) *pcbParam = outsz;' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLGetInfo(call_name, normal_db400_args):
c_main = ""
c_main += ' int isconvert = non_utf_isconvert_ordinal(fInfoType);' + "\n"
c_main += ' SQLINTEGER outsz = 0;' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' if (isconvert) {' + "\n"
c_main += ' outsz = non_utf_copy_out_hdbc(hdbc, sqlrc, (SQLCHAR *)rgbInfoValue, (SQLINTEGER)cbInfoValueMax);' + "\n"
c_main += ' if (pcbInfoValue) *pcbInfoValue = outsz;' + "\n"
c_main += ' }' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLGetPosition(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + "\n"
c_main += ' SQLCHAR * tmp1 = NULL;' + "\n"
c_main += ' srchLiteralLen = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&srchLiteral, (SQLINTEGER)srchLiteralLen, (SQLINTEGER)maxsz);' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&srchLiteral);' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLNativeSql(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER outsz = 0;' + "\n"
c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + "\n"
c_main += ' SQLCHAR * tmp1 = NULL;' + "\n"
c_main += ' cbSqlStrIn = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStrIn, (SQLINTEGER)cbSqlStrIn, (SQLINTEGER)maxsz);' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStrIn);' + "\n"
c_main += ' outsz = non_utf_copy_out_hdbc(hdbc, sqlrc, (SQLCHAR *)szSqlStr, (SQLINTEGER)cbSqlStrMax);' + "\n"
c_main += ' if (pcbSqlStr) *pcbSqlStr = outsz;' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLParamData(call_name, normal_db400_args):
c_main = ""
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLPrepare(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + "\n"
c_main += ' SQLCHAR * tmp1 = NULL;' + "\n"
c_main += ' cbSqlStr = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStr, (SQLINTEGER)cbSqlStr, (SQLINTEGER)maxsz);' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStr);' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLPrimaryKeys(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n"
c_main += ' SQLCHAR * tmp1 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp2 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp3 = NULL;' + "\n"
c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)cbTableQualifier, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)cbTableOwner, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)cbTableName, (SQLINTEGER)maxsz);' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLProcedureColumns(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n"
c_main += ' SQLCHAR * tmp1 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp2 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp3 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp4 = NULL;' + "\n"
c_main += ' cbProcQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szProcQualifier, (SQLINTEGER)cbProcQualifier, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbProcOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szProcOwner, (SQLINTEGER)cbProcOwner, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbProcName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szProcName, (SQLINTEGER)cbProcName, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbColumnName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName, (SQLINTEGER)cbColumnName, (SQLINTEGER)maxsz);' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szProcQualifier);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szProcOwner);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szProcName);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName);' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLProcedures(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n"
c_main += ' SQLCHAR * tmp1 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp2 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp3 = NULL;' + "\n"
c_main += ' cbProcQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szProcQualifier, (SQLINTEGER)cbProcQualifier, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbProcOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szProcOwner, (SQLINTEGER)cbProcOwner, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbProcName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szProcName, (SQLINTEGER)cbProcName, (SQLINTEGER)maxsz);' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szProcQualifier);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szProcOwner);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szProcName);' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLSetConnectAttr(call_name, normal_db400_args):
c_main = ""
c_main += ' int isconvert = non_utf_isconvert_ordinal(attrib);' + "\n"
c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + "\n"
c_main += ' SQLCHAR * tmp1 = NULL;' + "\n"
c_main += ' if (isconvert) {' + "\n"
c_main += ' inlen = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp1, (SQLCHAR **)&vParam, (SQLINTEGER)inlen, (SQLINTEGER)maxsz);' + "\n"
c_main += ' }' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' if (isconvert) {' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&vParam);' + "\n"
c_main += ' }' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLSetConnectOption(call_name, normal_db400_args):
c_main = ""
c_main += ' int isconvert = non_utf_isconvert_ordinal(fOption);' + "\n"
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n"
c_main += ' SQLINTEGER tmpsz = 0;' + "\n"
c_main += ' SQLCHAR * tmp1 = NULL;' + "\n"
c_main += ' if (isconvert) {' + "\n"
c_main += ' tmpsz = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp1, (SQLCHAR **)&vParam, (SQLINTEGER)SQL_NTS, (SQLINTEGER)maxsz);' + "\n"
c_main += ' }' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' if (isconvert) {' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&vParam);' + "\n"
c_main += ' }' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLSetCursorName(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n"
c_main += ' SQLCHAR * tmp1 = NULL;' + "\n"
c_main += ' cbCursor = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szCursor, (SQLINTEGER)cbCursor, (SQLINTEGER)maxsz);' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szCursor);' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLSetEnvAttr(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + "\n"
c_main += ' SQLCHAR * tmp1 = NULL;' + "\n"
c_main += ' if (fAttribute == SQL_ATTR_DBC_DEFAULT_LIB || fAttribute == SQL_ATTR_SAVEPOINT_NAME) {' + "\n"
c_main += ' cbParam = non_utf_copy_in_hdbc(0, (SQLCHAR **)&tmp1, (SQLCHAR **)&pParam, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + "\n"
c_main += ' }' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' if (fAttribute == SQL_ATTR_DBC_DEFAULT_LIB || fAttribute == SQL_ATTR_SAVEPOINT_NAME) {' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&pParam);' + "\n"
c_main += ' }' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLSpecialColumns(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n"
c_main += ' SQLCHAR * tmp1 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp2 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp3 = NULL;' + "\n"
c_main += ' cbTableQual = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQual, (SQLINTEGER)cbTableQual, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)cbTableOwner, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)cbTableName, (SQLINTEGER)maxsz);' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQual);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLStatistics(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n"
c_main += ' SQLCHAR * tmp1 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp2 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp3 = NULL;' + "\n"
c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)cbTableQualifier, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)cbTableOwner, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)cbTableName, (SQLINTEGER)maxsz);' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLTablePrivileges(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n"
c_main += ' SQLCHAR * tmp1 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp2 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp3 = NULL;' + "\n"
c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
def non_utf_SQLTables(call_name, normal_db400_args):
c_main = ""
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n"
c_main += ' SQLCHAR * tmp1 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp2 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp3 = NULL;' + "\n"
c_main += ' SQLCHAR * tmp4 = NULL;' + "\n"
c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + "\n"
c_main += ' cbTableType = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp4, (SQLCHAR **)&szTableType, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + "\n"
c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + "\n"
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp4, (SQLCHAR **)&szTableType);' + "\n"
c_main += ' return sqlrc;' + "\n"
c_main += '}' + "\n"
return c_main
# ===============================================
# special ILE CLI APIs
# ===============================================
# SQLRETURN ILE_SQLParamData( SQLHSTMT hstmt, SQLPOINTER * Value )
def ILE_SQLParamData_copy_var():
c_main = ""
c_main += ' /* returnPtr - API returns ILE SP pointer buffer (alias of PASE ptr) */ ' + "\n"
c_main += ' char returnBuffer[ sizeof(ILEpointer ) + 16 ];' + "\n"
c_main += ' ILEpointer *returnPtr = (ILEpointer *)ROUND_QUAD(returnBuffer);' + "\n"
return c_main
def ILE_SQLParamData_copy_in():
c_main = ""
c_main += ' /* returnPtr - ILE SP pointer buffer return area */ ' + "\n"
c_main += ' if (Value) {' + "\n"
c_main += ' arglist->Value.s.addr = (ulong) returnPtr;' + "\n"
c_main += ' }' + "\n"
return c_main
def ILE_SQLParamData_copy_out():
c_main = ""
c_main += ' /* returnPtr - ILE SP to PASE pointer */ ' + "\n"
c_main += ' if (Value) {' + "\n"
c_main += ' if (arglist->base.result.s_int32.r_int32 == SQL_NEED_DATA) {' + "\n"
c_main += ' *Value = _CVTSPP(returnPtr);' + "\n"
c_main += ' }' + "\n"
c_main += ' }' + "\n"
return c_main
# SQLRETURN ILE_SQLGetDescField( SQLHDESC hdesc, SQLSMALLINT rcdNum, SQLSMALLINT fieldID,
# SQLPOINTER fValue, SQLINTEGER fLength, SQLINTEGER * stLength )
def ILE_SQLGetDescField_copy_var():
c_main = ""
c_main += ' /* returnPtr - API returns ILE SP pointer buffer (alias of PASE ptr)' + "\n"
c_main += ' * Return ILE SP likely outside PASE mapable addr space.' + "\n"
c_main += ' * However, _CVTSPP is safe. The result is zero (null)' + "\n"
c_main += ' * if the input is a 16-byte null pointer or a tagged space pointer ' + "\n"
c_main += ' * that does not contain the teraspace address' + "\n"
c_main += ' * equivalent of some valid IBM PASE for i memory address.' + "\n"
c_main += ' * (I suspect options never used in years of PASE.' + "\n"
c_main += ' * Rochester CLI team was notified).' + "\n"
c_main += ' */' + "\n"
c_main += ' char returnBuffer[ sizeof(ILEpointer ) + 16 ];' + "\n"
c_main += ' ILEpointer *returnPtr = (ILEpointer *)ROUND_QUAD(returnBuffer);' + "\n"
return c_main
def ILE_SQLGetDescField_copy_in():
c_main = ""
c_main += ' /* returnPtr - ILE SP pointer buffer return area */ ' + "\n"
c_main += ' if (fValue) {' + "\n"
c_main += ' if (fieldID == SQL_DESC_DATA_PTR' + "\n"
c_main += ' || fieldID == SQL_DESC_LENGTH_PTR' + "\n"
c_main += ' || fieldID == SQL_DESC_INDICATOR_PTR)' + "\n"
c_main += ' {' + "\n"
c_main += ' arglist->fValue.s.addr = (ulong) returnPtr;' + "\n"
c_main += ' }' + "\n"
c_main += ' }' + "\n"
return c_main
def ILE_SQLGetDescField_copy_out():
c_main = ""
c_main += ' /* returnPtr - ILE SP to PASE pointer */ ' + "\n"
c_main += ' if (fValue) {' + "\n"
c_main += ' if (fieldID == SQL_DESC_DATA_PTR' + "\n"
c_main += ' || fieldID == SQL_DESC_LENGTH_PTR' + "\n"
c_main += ' || fieldID == SQL_DESC_INDICATOR_PTR)' + "\n"
c_main += ' {' + "\n"
c_main += ' *((void **)fValue) = _CVTSPP(returnPtr);' + "\n"
c_main += ' }' + "\n"
c_main += ' }' + "\n"
return c_main
# ===============================================
# pre-process CLI gen_cli_template.c
# (future ... if wide interface or not)
# ===============================================
pre = open(PaseSqlCli_file,"r")
ile_wide_api = {'nothing': 'nothing'}
for line in pre:
# start of SQL function ..
# SQLRETURN SQLxxx(
if "SQLRETURN SQL" in line:
# parse function
lesss = line.split("(")
parts = lesss[0].split(" ")
funcs = parts[1]
# forget
if "400" in funcs:
continue
# wide api
if "W" in funcs:
line_no_W = funcs.split("W")
assoc_name = line_no_W[0]
ile_wide_api[assoc_name] = funcs
# if call_name in ile_wide_api.values():
# print("ile_wide_api['" + assoc_name + "'] = '" + funcs + "'")
# ===============================================
# process CLI gen_cli_template.c
# ===============================================
f = open(PaseSqlCli_file,"r")
g = False
c400 = True
c400_CCSID = False
c400_not_wide = True
ile_or_custom_call = ""
ile_or_libdb400_call = ""
line_func = ""
libdb400_exp=""
PaseCliLibDB400_h_proto = ""
PaseCliLibDB400_c_symbol = ""
PaseCliLibDB400_c_main = ""
PaseCliAsync_h_struct = ""
PaseCliAsync_h_proto_async = ""
PaseCliAsync_h_proto_join = ""
PaseCliAsync_c_main = ""
PaseCliAny_h_proto = ""
PaseCliOnly400_h_proto = ""
PaseCliILE_h_proto = ""
PaseCliILE_c_symbol = ""
PaseCliCustom_h_proto = ""
PaseCliILE_h_struct = ""
PaseCliILE_c_main = ""
PaseCliDump_h_proto = ""
PaseCliDump_c_main = ""
for line in f:
# start of SQL function ..
# SQLRETURN SQLxxx(
if "SQLRETURN SQL" in line:
g = True
line_func = ""
if g:
# throw out change flags and comments
# SQLRETURN SQLPrimaryKeys ... /* @08A*/
# 0
line_no_comment = line.split("/")
split0 = line_no_comment[0]
line_func += split0
# end of function ..args..)
if not ")" in split0:
continue
else:
g = False
else:
continue
# ---------------
# parse function
# ---------------
parts = parse_method(line_func)
funcs = parts[0]
args = parts[1]
# SQLRETURN SQLPrimaryKeys
# 0 (1 or 2)
call_retv = funcs[0] + funcs[1]
call_name = funcs[2]
struct_name = call_name + "Struct"
struct_ile_name = call_name + "IleCallStruct"
struct_ile_sig = call_name + "IleSigStruct"
struct_ile_flag = call_name + "Loaded"
struct_ile_buf = call_name + "Buf"
struct_ile_ptr = call_name + "Ptr"
# ---------------
# custom function (super api)
# ---------------
c400_not_wide = True
c400_CCSID = False
c400 = True
ile_or_custom_call = "custom_"
ile_or_libdb400_call = "libdb400_"
if "SQLOverrideCCSID400" in call_name:
c400_CCSID = True
if "SQL400" in call_name:
c400 = False
if c400:
ile_or_custom_call = "ILE_"
if "W" in call_name:
ile_or_libdb400_call = "ILE_"
c400_not_wide = False
# ---------------
# arguments (params)
# ---------------
idx = 0
comma = ","
semi = ";"
argtype1st = ""
argname1st = ""
normal_call_types = ""
normal_call_args = ""
normal_db400_args = ""
async_struct_types = " SQLRETURN sqlrc;"
async_call_args = ""
async_db400_args = ""
async_copyin_args = ""
ILE_struct_sigs = ""
ILE_struct_types = "ILEarglist_base base;"
ILE_copyin_args = ""
dump_args = ""
dump_sigs = ""
for arg in args:
idx += 1
if idx == len(args):
comma = ""
# SQLHSTMT hstmt
# 0 1
# SQLCHAR * szTableQualifier
# 0 1 2
argfull = ' '.join(arg)
argsig = arg[0] + arg[1]
argname = arg[2]
if idx == 1:
argtype1st = arg[0];
argname1st = arg[2];
sigile = ''
ilefull = argfull
if arg[1] == '*':
sigile = 'ARG_MEMPTR'
ilefull = 'ILEpointer' + ' ' + arg[2]
elif arg[0] == 'PTR':
sigile = 'ARG_MEMPTR'
ilefull = 'ILEpointer' + ' ' + arg[2]
elif arg[0] == 'SQLHWND':
sigile = 'ARG_MEMPTR'
ilefull = 'ILEpointer' + ' ' + arg[2]
elif arg[0] == 'SQLPOINTER':
sigile = 'ARG_MEMPTR'
ilefull = 'ILEpointer' + ' ' + arg[2]
elif arg[0] == 'SQLCHAR':
sigile = 'ARG_UINT8'
elif arg[0] == 'SQLWCHAR':
sigile = 'ARG_UINT8'
elif arg[0] == 'SQLSMALLINT':
sigile = 'ARG_INT16'
elif arg[0] == 'SQLUSMALLINT':
sigile = 'ARG_UINT16'
elif arg[0] == 'SQLSMALLINT':
sigile = 'ARG_INT16'
elif arg[0] == 'SQLINTEGER':
sigile = 'ARG_INT32'
elif arg[0] == 'SQLUINTEGER':
sigile = 'ARG_UINT32'
elif arg[0] == 'SQLDOUBLE':
sigile = 'ARG_FLOAT64'
elif arg[0] == 'SQLREAL':
sigile = 'ARG_FLOAT32'
elif arg[0] == 'HENV':
sigile = 'ARG_INT32'
elif arg[0] == 'HDBC':
sigile = 'ARG_INT32'
elif arg[0] == 'HSTMT':
sigile = 'ARG_INT32'
elif arg[0] == 'HDESC':
sigile = 'ARG_INT32'
elif arg[0] == 'SQLHANDLE':
sigile = 'ARG_INT32'
elif arg[0] == 'SQLHENV':
sigile = 'ARG_INT32'
elif arg[0] == 'SQLHDBC':
sigile = 'ARG_INT32'
elif arg[0] == 'SQLHSTMT':
sigile = 'ARG_INT32'
elif arg[0] == 'SQLHDESC':
sigile = 'ARG_INT32'
elif arg[0] == 'RETCODE':
sigile = 'ARG_INT32'
elif arg[0] == 'SQLRETURN':
sigile = 'ARG_INT32'
elif arg[0] == 'SFLOAT':
sigile = 'ARG_FLOAT32'
# each SQL function override
# SQLRETURN SQLPrimaryKeys( SQLHSTMT hstmt, SQLCHAR * szTableQualifier, SQLSMALLINT cbTableQualifier, ...
# -------------------------------------------------------------------------
normal_call_args += ' ' + argfull + comma
# each SQL function call libdb400
# sqlrc = libdb400_SQLPrimaryKeys( hstmt, szTableQualifier, cbTableQualifier, ...
# ------------------------------------------
normal_db400_args += ' ' + argname + comma
# SQLRETURN (*libdb400_SQLPrimaryKeys)(SQLHSTMT,SQLCHAR*,SQLSMALLINT, ...
# ------------------------------
normal_call_types += ' ' + argsig + comma
# Dump args and sigs
#
dump_args += ' ' + argname
dump_sigs += ' ' + argsig
# ILE call structure
ILE_struct_types += ' ' + ilefull + semi
# ILE call signature
ILE_struct_sigs += ' ' + sigile + comma
# ILE copyin params
if sigile == 'ARG_MEMPTR':
ILE_copyin_args += ' arglist->' + argname + '.s.addr = (ulong) ' + argname + ";" + "\n"
else:
ILE_copyin_args += ' arglist->' + argname + ' = (' + argsig + ') ' + argname + ";" + "\n"
# each SQL async struct
# typedef struct SQLPrimaryKeysStruct { SQLRETURN sqlrc; SQLHSTMT hstmt; ...
# --------------------------------
async_struct_types += ' ' + argfull + semi
# each SQL asyn call libdb400
# myptr->sqlrc = libdb400_SQLPrimaryKeys( myptr->hstmt, myptr->szTableQualifier, myptr->cbTableQualifier, ...
# ------------------------------------------
async_db400_args += ' myptr->' + argname + comma
# each SQL asyn copyin parms
# myptr->hstmt = hstmt;
# myptr->szTableQualifier = szTableQualifier;
# myptr->cbTableQualifier = cbTableQualifier;
# ...
# ------------------------------------------
async_copyin_args += ' myptr->' + argname + " = " + argname + ";" + "\n"
# ===============================================
# standard dumping function
# ===============================================
PaseCliDump_h_proto += "void dump_" + call_name + '(SQLRETURN sqlrc, ' + normal_call_args + ' );' + "\n"
PaseCliDump_c_main += "void dump_" + call_name + '(SQLRETURN sqlrc, ' + normal_call_args + ' ) {' + "\n"
PaseCliDump_c_main += ' if (dev_go(sqlrc,"'+call_name.lower()+'")) {' + "\n"
PaseCliDump_c_main += ' char mykey[256];' + "\n"
PaseCliDump_c_main += ' printf_key(mykey,"' + call_name + '");' + "\n"
PaseCliDump_c_main += ' printf_clear();' + "\n"
PaseCliDump_c_main += ' printf_sqlrc_head_foot((char *)&mykey, sqlrc, 1);' + "\n"
PaseCliDump_c_main += ' printf_stack(mykey);' + "\n"
PaseCliDump_c_main += ' printf_sqlrc_status((char *)&mykey, sqlrc);' + "\n"
args = dump_args.split()
sigs = dump_sigs.split()
dump_handle = ''
dump_type = ''
i = 0
for arg in args:
sig = sigs[i]
PaseCliDump_c_main += ' printf_format("%s.parm %s %s 0x%p (%d)\\n",mykey,"'+sig+'","'+arg+'",'+arg+','+arg+');' + "\n"
if '*' in sig or 'SQLPOINTER' in sig:
PaseCliDump_c_main += ' printf_hexdump(mykey,'+arg+',80);' + "\n"
elif 'SQLHDBC' in sig:
dump_handle = arg
dump_type = 'SQL_HANDLE_DBC'
elif 'SQLHSTMT' in sig:
dump_handle = arg
dump_type = 'SQL_HANDLE_STMT'
elif 'SQLHDESC' in sig:
dump_handle = arg
dump_type = 'SQL_HANDLE_DESC'
i += 1
PaseCliDump_c_main += ' printf_sqlrc_head_foot((char *)&mykey, sqlrc, 0);' + "\n"
PaseCliDump_c_main += ' dev_dump();' + "\n"
PaseCliDump_c_main += ' if (sqlrc < SQL_SUCCESS) {' + "\n"
if 'SQL' in dump_type:
PaseCliDump_c_main += ' printf_sql_diag('+dump_type +','+dump_handle+');' + "\n"
PaseCliDump_c_main += ' printf_force_SIGQUIT((char *)&mykey);' + "\n"
PaseCliDump_c_main += ' }' + "\n"
PaseCliDump_c_main += ' }' + "\n"
PaseCliDump_c_main += '}' + "\n"
# ===============================================
# non-async SQL interfaces with lock added
# ===============================================
if c400:
# each SQL400 function special (header)
# SQLRETURN SQL400Environment( SQLINTEGER * ohnd, SQLPOINTER options )
#
PaseCliAny_h_proto += " * " + call_retv + ' ' + call_name + '(' + normal_call_args + ' );' + "\n"
# ===============================================
# libdb400 call (here adc tony)
# ===============================================
# SQLRETURN custom_SQLOverrideCCSID400( SQLINTEGER newCCSID )
if c400_CCSID:
PaseCliCustom_h_proto += call_retv + ' ' + "custom_" + call_name + '(' + normal_call_args + ' );' + "\n"
else:
# old libdb400.a (non-utf)
PaseCliLibDB400_h_proto += call_retv + ' libdb400_' + call_name + '(' + normal_call_args + ' );' + "\n"
# main
PaseCliLibDB400_c_main += call_retv + ' libdb400_' + call_name + '(' + normal_call_args + ' ) {' + "\n"
PaseCliLibDB400_c_main += ' SQLRETURN sqlrc = SQL_SUCCESS;' + "\n"
if 'W' in call_name:
PaseCliLibDB400_c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
PaseCliLibDB400_c_main += " return sqlrc;" + "\n"
PaseCliLibDB400_c_main += '}' + "\n"
else:
if 'SQLColAttributes' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLColAttributes(call_name, normal_db400_args)
elif 'SQLColumnPrivileges' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLColumnPrivileges(call_name, normal_db400_args)
elif 'SQLColumns' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLColumns(call_name, normal_db400_args)
elif 'SQLConnect' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLConnect(call_name, normal_db400_args)
elif 'SQLDataSources' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLDataSources(call_name, normal_db400_args)
elif 'SQLDescribeCol' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLDescribeCol(call_name, normal_db400_args)
elif 'SQLDriverConnect' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLDriverConnect(call_name, normal_db400_args)
elif 'SQLError' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLError(call_name, normal_db400_args)
elif 'SQLExecDirect' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLExecDirect(call_name, normal_db400_args)
elif 'SQLForeignKeys' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLForeignKeys(call_name, normal_db400_args)
elif 'SQLGetConnectAttr' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLGetConnectAttr(call_name, normal_db400_args)
elif 'SQLGetConnectOption' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLGetConnectOption(call_name, normal_db400_args)
elif 'SQLGetCursorName' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLGetCursorName(call_name, normal_db400_args)
elif 'SQLGetDescField' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLGetDescField(call_name, normal_db400_args)
elif 'SQLGetDescRec' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLGetDescRec(call_name, normal_db400_args)
elif 'SQLGetDiagField' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLGetDiagField(call_name, normal_db400_args)
elif 'SQLGetDiagRec' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLGetDiagRec(call_name, normal_db400_args)
elif 'SQLGetEnvAttr' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLGetEnvAttr(call_name, normal_db400_args)
elif 'SQLGetInfo' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLGetInfo(call_name, normal_db400_args)
elif 'SQLGetPosition' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLGetPosition(call_name, normal_db400_args)
elif 'SQLNativeSql' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLNativeSql(call_name, normal_db400_args)
elif 'SQLParamData' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLParamData(call_name, normal_db400_args)
elif 'SQLPrepare' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLPrepare(call_name, normal_db400_args)
elif 'SQLPrimaryKeys' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLPrimaryKeys(call_name, normal_db400_args)
elif 'SQLProcedureColumns' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLProcedureColumns(call_name, normal_db400_args)
elif 'SQLProcedures' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLProcedures(call_name, normal_db400_args)
elif 'SQLSetConnectAttr' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLSetConnectAttr(call_name, normal_db400_args)
elif 'SQLSetConnectOption' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLSetConnectOption(call_name, normal_db400_args)
elif 'SQLSetCursorName' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLSetCursorName(call_name, normal_db400_args)
elif 'SQLSetEnvAttr' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLSetEnvAttr(call_name, normal_db400_args)
elif 'SQLSpecialColumns' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLSpecialColumns(call_name, normal_db400_args)
elif 'SQLStatistics' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLStatistics(call_name, normal_db400_args)
elif 'SQLTablePrivileges' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLTablePrivileges(call_name, normal_db400_args)
elif 'SQLTables' in call_name:
PaseCliLibDB400_c_main += non_utf_SQLTables(call_name, normal_db400_args)
else:
PaseCliLibDB400_c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n"
PaseCliLibDB400_c_main += " return sqlrc;" + "\n"
PaseCliLibDB400_c_main += '}' + "\n"
libdb400_exp += "libdb400_" + call_name + "\n"
else:
# each SQL400 function special (header)
# SQLRETURN SQL400Environment( SQLINTEGER * ohnd, SQLPOINTER options )
#
PaseCliOnly400_h_proto += call_retv + ' ' + call_name + '(' + normal_call_args + ' );' + "\n"
PaseCliCustom_h_proto += call_retv + ' ' + "custom_" + call_name + '(' + normal_call_args + ' );' + "\n"
# export special libdb400.a
libdb400_exp += call_name + "\n"
# each SQL function override
# SQLRETURN SQLAllocEnv( SQLHENV * phenv )
# {
# }
if c400_CCSID:
PaseCliAsync_c_main += 'int SQLOverrideCCSID400(int newCCSID)' + "\n"
else:
PaseCliAsync_c_main += call_retv + ' ' + call_name + '(' + normal_call_args + ' )' + "\n"
PaseCliAsync_c_main += "{" + "\n"
PaseCliAsync_c_main += " SQLRETURN sqlrc = SQL_SUCCESS;" + "\n"
# special handling routines
if call_name == "SQLAllocEnv":
PaseCliAsync_c_main += PaseCliAsync_c_main_SQLAllocEnv(ile_or_custom_call, call_name, normal_db400_args)
elif call_name == "SQLAllocConnect":
PaseCliAsync_c_main += PaseCliAsync_c_main_SQLAllocConnect(ile_or_custom_call, call_name, normal_db400_args)
elif call_name == "SQLAllocStmt":
PaseCliAsync_c_main += PaseCliAsync_c_main_SQLAllocStmt(ile_or_custom_call, call_name, normal_db400_args)
elif call_name == "SQLAllocHandle":
PaseCliAsync_c_main += PaseCliAsync_c_main_SQLAllocHandle(ile_or_custom_call, call_name, normal_db400_args)
elif call_name == "SQLFreeEnv":
PaseCliAsync_c_main += PaseCliAsync_c_main_SQLFreeEnv(ile_or_custom_call, call_name, normal_db400_args)
elif call_name == "SQLFreeConnect":
PaseCliAsync_c_main += PaseCliAsync_c_main_SQLFreeConnect(ile_or_custom_call, call_name, normal_db400_args)
elif call_name == "SQLFreeStmt":
PaseCliAsync_c_main += PaseCliAsync_c_main_SQLFreeStmt(ile_or_custom_call, call_name, normal_db400_args)
elif call_name == "SQLFreeHandle":
PaseCliAsync_c_main += PaseCliAsync_c_main_SQLFreeHandle(ile_or_custom_call, call_name, normal_db400_args)
# SQLRETURN SQLOverrideCCSID400( SQLINTEGER newCCSID )
elif c400_CCSID:
PaseCliAsync_c_main += " sqlrc = custom_" + call_name + '(' + normal_db400_args + ' );' + "\n"
# all other CLI APIs
else:
# normal cli function
PaseCliAsync_c_main += " int myccsid = init_CCSID400(0);" + "\n"
if call_name == "SQLDisconnect":
PaseCliAsync_c_main += SQLDisconnect_check_persistent("hdbc","return SQL_ERROR;", "/* return now */")
if argtype1st == "SQLHENV":
if ile_or_custom_call == "custom_":
PaseCliAsync_c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
else:
PaseCliAsync_c_main += " switch(myccsid) {" + "\n"
PaseCliAsync_c_main += ' case 1208: /* UTF-8 */' + "\n"
PaseCliAsync_c_main += ' case 1200: /* UTF-16 */' + "\n"
PaseCliAsync_c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
PaseCliAsync_c_main += " break;" + "\n"
PaseCliAsync_c_main += ' default:' + "\n"
PaseCliAsync_c_main += " sqlrc = libdb400_" + call_name + '(' + normal_db400_args + ' );' + "\n"
PaseCliAsync_c_main += " break;" + "\n"
PaseCliAsync_c_main += " }" + "\n"
# dump trace
PaseCliAsync_c_main += " if (init_cli_trace()) {" + "\n"
PaseCliAsync_c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n"
PaseCliAsync_c_main += " }" + "\n"
elif argtype1st == "SQLHDBC":
PaseCliAsync_c_main += " init_table_lock(" + argname1st + ", 0);" + "\n"
if ile_or_custom_call == "custom_":
PaseCliAsync_c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
else:
PaseCliAsync_c_main += " switch(myccsid) {" + "\n"
PaseCliAsync_c_main += ' case 1208: /* UTF-8 */' + "\n"
PaseCliAsync_c_main += ' case 1200: /* UTF-16 */' + "\n"
PaseCliAsync_c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
PaseCliAsync_c_main += " break;" + "\n"
PaseCliAsync_c_main += ' default:' + "\n"
PaseCliAsync_c_main += " sqlrc = libdb400_" + call_name + '(' + normal_db400_args + ' );' + "\n"
PaseCliAsync_c_main += " break;" + "\n"
PaseCliAsync_c_main += " }" + "\n"
# dump trace
PaseCliAsync_c_main += " if (init_cli_trace()) {" + "\n"
PaseCliAsync_c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n"
PaseCliAsync_c_main += " }" + "\n"
PaseCliAsync_c_main += " init_table_unlock(" + argname1st + ", 0);" + "\n"
elif argtype1st == "SQLHSTMT":
PaseCliAsync_c_main += " init_table_lock(" + argname1st + ", 1);" + "\n"
if ile_or_custom_call == "custom_":
PaseCliAsync_c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
else:
PaseCliAsync_c_main += " switch(myccsid) {" + "\n"
PaseCliAsync_c_main += ' case 1208: /* UTF-8 */' + "\n"
PaseCliAsync_c_main += ' case 1200: /* UTF-16 */' + "\n"
PaseCliAsync_c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
PaseCliAsync_c_main += " break;" + "\n"
PaseCliAsync_c_main += ' default:' + "\n"
PaseCliAsync_c_main += " sqlrc = libdb400_" + call_name + '(' + normal_db400_args + ' );' + "\n"
PaseCliAsync_c_main += " break;" + "\n"
PaseCliAsync_c_main += " }" + "\n"
# dump trace
PaseCliAsync_c_main += " if (init_cli_trace()) {" + "\n"
PaseCliAsync_c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n"
PaseCliAsync_c_main += " }" + "\n"
PaseCliAsync_c_main += " init_table_unlock(" + argname1st + ", 1);" + "\n"
elif argtype1st == "SQLHDESC":
PaseCliAsync_c_main += " init_table_lock(" + argname1st + ", 1);" + "\n"
if ile_or_custom_call == "custom_":
PaseCliAsync_c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
else:
PaseCliAsync_c_main += " switch(myccsid) {" + "\n"
PaseCliAsync_c_main += ' case 1208: /* UTF-8 */' + "\n"
PaseCliAsync_c_main += ' case 1200: /* UTF-16 */' + "\n"
PaseCliAsync_c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
PaseCliAsync_c_main += " break;" + "\n"
PaseCliAsync_c_main += ' default:' + "\n"
PaseCliAsync_c_main += " sqlrc = libdb400_" + call_name + '(' + normal_db400_args + ' );' + "\n"
PaseCliAsync_c_main += " break;" + "\n"
PaseCliAsync_c_main += " }" + "\n"
# dump trace
PaseCliAsync_c_main += " if (init_cli_trace()) {" + "\n"
PaseCliAsync_c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n"
PaseCliAsync_c_main += " }" + "\n"
PaseCliAsync_c_main += " init_table_unlock(" + argname1st + ", 1);" + "\n"
else:
if ile_or_custom_call == "custom_":
PaseCliAsync_c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
else:
PaseCliAsync_c_main += " switch(myccsid) {" + "\n"
PaseCliAsync_c_main += ' case 1208: /* UTF-8 */' + "\n"
PaseCliAsync_c_main += ' case 1200: /* UTF-16 */' + "\n"
PaseCliAsync_c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n"
PaseCliAsync_c_main += " break;" + "\n"
PaseCliAsync_c_main += ' default:' + "\n"
PaseCliAsync_c_main += " sqlrc = libdb400_" + call_name + '(' + normal_db400_args + ' );' + "\n"
PaseCliAsync_c_main += " break;" + "\n"
PaseCliAsync_c_main += " }" + "\n"
# dump trace
PaseCliAsync_c_main += " if (init_cli_trace()) {" + "\n"
PaseCliAsync_c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n"
PaseCliAsync_c_main += " }" + "\n"
# common code
PaseCliAsync_c_main += " return sqlrc;" + "\n"
PaseCliAsync_c_main += "}" + "\n"
# ===============================================
# ILE call
# ===============================================
if c400 and c400_CCSID == False:
PaseCliILE_h_proto += call_retv + ' ILE_' + call_name + '(' + normal_call_args + ' );' + "\n"
PaseCliILE_h_struct += 'typedef struct ' + struct_ile_name + ' {' + ILE_struct_types + ' } ' + struct_ile_name + ';' + "\n";
PaseCliILE_c_symbol += 'SQLINTEGER ' + struct_ile_flag + ';' + "\n"
PaseCliILE_c_symbol += 'SQLCHAR ' + struct_ile_buf + '[132];' + "\n"
PaseCliILE_c_main += call_retv + ' ILE_' + call_name + '(' + normal_call_args + ' )' + "\n"
PaseCliILE_c_main += '{' + "\n"
PaseCliILE_c_main += ' int rc = 0;' + "\n"
PaseCliILE_c_main += ' SQLRETURN sqlrc = SQL_SUCCESS;' + "\n"
if 'SQLParamData' in call_name:
PaseCliILE_c_main += ILE_SQLParamData_copy_var()
if 'SQLGetDescField' in call_name:
PaseCliILE_c_main += ILE_SQLGetDescField_copy_var()
PaseCliILE_c_main += ' int actMark = 0;' + "\n"
PaseCliILE_c_main += ' char * ileSymPtr = (char *) NULL;' + "\n"
PaseCliILE_c_main += ' ' + struct_ile_name + ' * arglist = (' + struct_ile_name + ' *) NULL;' + "\n"
PaseCliILE_c_main += ' char buffer[ sizeof(' + struct_ile_name + ') + 16 ];' + "\n"
PaseCliILE_c_main += ' static arg_type_t ' + struct_ile_sig + '[] = {' + ILE_struct_sigs + ', ARG_END };' + "\n";
PaseCliILE_c_main += ' arglist = (' + struct_ile_name + ' *)ROUND_QUAD(buffer);' + "\n"
PaseCliILE_c_main += ' ileSymPtr = (char *)ROUND_QUAD(&' + struct_ile_buf + ');' + "\n"
PaseCliILE_c_main += ' memset(buffer,0,sizeof(buffer));' + "\n"
PaseCliILE_c_main += ' actMark = init_cli_srvpgm();' + "\n"
PaseCliILE_c_main += ' if (!'+ struct_ile_flag +') {' + "\n"
PaseCliILE_c_main += ' rc = _ILESYM((ILEpointer *)ileSymPtr, actMark, "' + call_name + '");' + "\n"
PaseCliILE_c_main += ' if (rc < 0) {' + "\n"
PaseCliILE_c_main += ' return SQL_ERROR;' + "\n"
PaseCliILE_c_main += ' }' + "\n"
PaseCliILE_c_main += ' ' + struct_ile_flag + ' = 1;' + "\n"
PaseCliILE_c_main += ' }' + "\n"
PaseCliILE_c_main += ILE_copyin_args
if 'SQLParamData' in call_name:
PaseCliILE_c_main += ILE_SQLParamData_copy_in()
if 'SQLGetDescField' in call_name:
PaseCliILE_c_main += ILE_SQLGetDescField_copy_in()
PaseCliILE_c_main += ' rc = _ILECALL((ILEpointer *)ileSymPtr, &arglist->base, ' + struct_ile_sig + ', RESULT_INT32);' + "\n"
PaseCliILE_c_main += ' if (rc != ILECALL_NOERROR) {' + "\n"
PaseCliILE_c_main += ' return SQL_ERROR;' + "\n"
PaseCliILE_c_main += ' }' + "\n"
if 'SQLParamData' in call_name:
PaseCliILE_c_main += ILE_SQLParamData_copy_out()
if 'SQLGetDescField' in call_name:
PaseCliILE_c_main += ILE_SQLGetDescField_copy_out()
PaseCliILE_c_main += ' return arglist->base.result.s_int32.r_int32;' + "\n"
PaseCliILE_c_main += '}' + "\n"
# ===============================================
# NO async SQL interfaces with thread
# ===============================================
if call_name == "SQLAllocEnv":
continue
elif call_name == "SQLAllocConnect":
continue
elif call_name == "SQLAllocStmt":
continue
elif call_name == "SQLAllocHandle":
continue
elif call_name == "SQLFreeEnv":
continue
elif call_name == "SQLFreeConnect":
continue
elif call_name == "SQLFreeStmt":
continue
elif call_name == "SQLFreeHandle":
continue
elif c400_CCSID:
continue
# ===============================================
# async SQL interfaces with thread
# ===============================================
async_call_args = normal_call_args + ', void * callback'
async_struct_types += ' void * callback;'
async_copyin_args += ' myptr->callback = callback;' + "\n"
# each SQL function async (header)
# SQLRETURN SQLSpecialColumnsAsync ( SQLHSTMT hstmt, SQLSMALLINT fColType, ... , void * callback )
# void (*callback)(SQLSpecialColumnsStruct* )
# SQLSpecialColumnsStruct * SQLSpecialColumnsJoin (pthread_t tid, SQLINTEGER flag)
#
tmp_PaseCliAsync_comment = '/* void ' + call_name + 'Callback(' + struct_name + '* ); */'
PaseCliAsync_h_proto_async += 'pthread_t ' + call_name + 'Async (' + async_call_args + ' );' + "\n"
PaseCliAsync_h_proto_join += tmp_PaseCliAsync_comment + "\n"
PaseCliAsync_h_proto_join += struct_name + ' * ' + call_name + 'Join (pthread_t tid, SQLINTEGER flag);' + "\n"
# export special libdb400.a
libdb400_exp += call_name + 'Async' + "\n"
libdb400_exp += call_name + 'Join' + "\n"
if c400:
libdb400_exp += 'ILE_' + call_name + "\n"
# each SQL function async
# typedef struct SQLAllocEnvStruct {
# SQLRETURN sqlrc;
# SQLHENV * phenv;
# } SQLAllocEnvStruct;
#
#
PaseCliAsync_h_struct += 'typedef struct ' + struct_name + ' {' + async_struct_types + ' } ' + struct_name + ';' + "\n";
# each SQL function async
# void * SQLAllocEnvThread(void *ptr)
# {
# void (*callback)(SQLSpecialColumnsStruct* )
# }
PaseCliAsync_c_main += 'void * ' + call_name + 'Thread (void *ptr)' + "\n"
PaseCliAsync_c_main += "{" + "\n"
PaseCliAsync_c_main += ' SQLRETURN sqlrc = SQL_SUCCESS;' + "\n"
PaseCliAsync_c_main += " int myccsid = init_CCSID400(0);" + "\n"
PaseCliAsync_c_main += ' ' + struct_name + ' * myptr = (' + struct_name + ' *) ptr;' + "\n"
if call_name == "SQLDisconnect":
PaseCliAsync_c_main += SQLDisconnect_check_persistent("myptr->hdbc","pthread_exit((void *)myptr);","myptr->sqlrc = SQL_ERROR;")
if argtype1st == "SQLHENV":
PaseCliAsync_c_main += " /* not lock */" + "\n"
elif argtype1st == "SQLHDBC":
PaseCliAsync_c_main += " init_table_lock(myptr->" + argname1st + ", 0);" + "\n"
elif argtype1st == "SQLHSTMT":
PaseCliAsync_c_main += " init_table_lock(myptr->" + argname1st + ", 1);" + "\n"
elif argtype1st == "SQLHDESC":
PaseCliAsync_c_main += " init_table_lock(myptr->" + argname1st + ", 1);" + "\n"
if ile_or_custom_call == "custom_":
PaseCliAsync_c_main += " myptr->sqlrc = " + ile_or_custom_call + call_name + '(' + async_db400_args + ' );' + "\n"
else:
# CLI call
PaseCliAsync_c_main += " switch(myccsid) {" + "\n"
PaseCliAsync_c_main += ' case 1208: /* UTF-8 */' + "\n"
PaseCliAsync_c_main += ' case 1200: /* UTF-16 */' + "\n"
PaseCliAsync_c_main += " myptr->sqlrc = " + ile_or_custom_call + call_name + '(' + async_db400_args + ' );' + "\n"
PaseCliAsync_c_main += " break;" + "\n"
PaseCliAsync_c_main += ' default:' + "\n"
PaseCliAsync_c_main += " myptr->sqlrc = libdb400_" + call_name + '(' + async_db400_args + ' );' + "\n"
PaseCliAsync_c_main += " break;" + "\n"
PaseCliAsync_c_main += " }" + "\n"
# dump trace
PaseCliAsync_c_main += " if (init_cli_trace()) {" + "\n"
PaseCliAsync_c_main += " dump_" + call_name + '(myptr->sqlrc, ' + async_db400_args + ' );' + "\n"
PaseCliAsync_c_main += " }" + "\n"
if argtype1st == "SQLHENV":
PaseCliAsync_c_main += " /* not lock */" + "\n"
elif argtype1st == "SQLHDBC":
PaseCliAsync_c_main += " init_table_unlock(myptr->" + argname1st + ", 0);" + "\n"
elif argtype1st == "SQLHSTMT":
PaseCliAsync_c_main += " init_table_unlock(myptr->" + argname1st + ", 1);" + "\n"
elif argtype1st == "SQLHDESC":
PaseCliAsync_c_main += " init_table_unlock(myptr->" + argname1st + ", 1);" + "\n"
PaseCliAsync_c_main += ' ' + tmp_PaseCliAsync_comment + "\n"
PaseCliAsync_c_main += ' if (myptr->callback) {' + "\n"
PaseCliAsync_c_main += ' void (*ptrFunc)(' + struct_name + '* ) = myptr->callback;' + "\n"
PaseCliAsync_c_main += ' ptrFunc( myptr );' + "\n"
PaseCliAsync_c_main += " }" + "\n"
PaseCliAsync_c_main += " pthread_exit((void *)myptr);" + "\n"
PaseCliAsync_c_main += "}" + "\n"
# each SQL function async
# pthread_t SQLSpecialColumnsAsync ( SQLHSTMT hstmt, SQLSMALLINT fColType, ... , void * callback )
# {
# }
PaseCliAsync_c_main += 'pthread_t ' + call_name + 'Async (' + async_call_args + ' )' + "\n"
PaseCliAsync_c_main += '{' + "\n"
PaseCliAsync_c_main += ' int rc = 0;' + "\n"
PaseCliAsync_c_main += ' pthread_t tid = 0;' + "\n"
PaseCliAsync_c_main += ' ' + struct_name + ' * myptr = (' + struct_name + ' *) malloc(sizeof(' + struct_name + '));' + "\n"
PaseCliAsync_c_main += ' myptr->sqlrc = SQL_SUCCESS;' + "\n"
PaseCliAsync_c_main += async_copyin_args
PaseCliAsync_c_main += ' rc = pthread_create(&tid, NULL, '+ call_name + 'Thread, (void *)myptr);' + "\n"
PaseCliAsync_c_main += ' return tid;' + "\n"
PaseCliAsync_c_main += '}' + "\n"
# each SQL function async
# SQLSpecialColumnsStruct * SQLSpecialColumnsJoin (pthread_t tid, SQLINTEGER flag)
# {
# }
PaseCliAsync_c_main += struct_name + ' * ' + call_name + 'Join (pthread_t tid, SQLINTEGER flag)' + "\n"
PaseCliAsync_c_main += "{" + "\n"
PaseCliAsync_c_main += " " + struct_name + " * myptr = (" + struct_name + " *) NULL;" + "\n"
PaseCliAsync_c_main += " int active = 0;" + "\n"
if argtype1st == "SQLHENV":
PaseCliAsync_c_main += " /* not lock */" + "\n"
elif argtype1st == "SQLHDBC":
PaseCliAsync_c_main += " active = init_table_in_progress(tid, 0);" + "\n"
elif argtype1st == "SQLHSTMT":
PaseCliAsync_c_main += " active = init_table_in_progress(tid, 1);" + "\n"
elif argtype1st == "SQLHDESC":
PaseCliAsync_c_main += " active = init_table_in_progress(tid, 1);" + "\n"
PaseCliAsync_c_main += " if (flag == SQL400_FLAG_JOIN_WAIT || !active) {" + "\n"
PaseCliAsync_c_main += " pthread_join(tid,(void**)&myptr);" + "\n"
PaseCliAsync_c_main += " } else {" + "\n"
PaseCliAsync_c_main += " return (" + struct_name + " *) NULL;" + "\n"
PaseCliAsync_c_main += " }" + "\n"
PaseCliAsync_c_main += " return myptr;" + "\n"
PaseCliAsync_c_main += "}" + "\n"
# ===============================================
# write files
# ===============================================
# pase includes
file_pase_incl = ""
file_pase_incl += "#include <stdio.h>" + "\n"
file_pase_incl += "#include <stdlib.h>" + "\n"
file_pase_incl += "#include <unistd.h>" + "\n"
file_pase_incl += "#include <dlfcn.h>" + "\n"
file_pase_incl += "#include <sqlcli1.h>" + "\n"
file_pase_incl += "#include <as400_types.h>" + "\n"
file_pase_incl += "#include <as400_protos.h>" + "\n"
# new libdb400 includes
file_local_incl = ""
file_local_incl += '#include "PaseCliInit.h"' + "\n"
file_local_incl += '#include "PaseCliAsync.h"' + "\n"
# write PaseCliILE_gen.c
file_PaseCliILE_c = ""
file_PaseCliILE_c += file_pase_incl
file_PaseCliILE_c += file_local_incl
file_PaseCliILE_c += "" + "\n"
file_PaseCliILE_c += ' /* gcc compiler' + "\n"
file_PaseCliILE_c += ' * as400_types.h (edit change required)' + "\n"
file_PaseCliILE_c += ' * #if defined( __GNUC__ )' + "\n"
file_PaseCliILE_c += ' * long double align __attribute__((aligned(16)));' + "\n"
file_PaseCliILE_c += ' * #else ' + "\n"
file_PaseCliILE_c += ' * long double;' + "\n"
file_PaseCliILE_c += ' * #endif ' + "\n"
file_PaseCliILE_c += ' * ' + "\n"
file_PaseCliILE_c += ' * Use we also need cast ulong to match size of pointer 32/64 ' + "\n"
file_PaseCliILE_c += ' * arglist->ohnd.s.addr = (ulong) ohnd;' + "\n"
file_PaseCliILE_c += ' */' + "\n"
file_PaseCliILE_c += "" + "\n"
file_PaseCliILE_c += '#define ROUND_QUAD(x) (((size_t)(x) + 0xf) & ~0xf)' + "\n"
file_PaseCliILE_c += "" + "\n"
file_PaseCliILE_c += PaseCliILE_c_symbol
file_PaseCliILE_c += "" + "\n"
file_PaseCliILE_c += "/* ILE call structures */" + "\n"
file_PaseCliILE_c += "" + "\n"
file_PaseCliILE_c += PaseCliILE_h_struct + "\n"
file_PaseCliILE_c += "" + "\n"
file_PaseCliILE_c += PaseCliILE_c_main
file_PaseCliILE_c += "" + "\n"
with open("PaseCliILE_gen.c", "w") as text_file:
text_file.write(file_PaseCliILE_c)
# write PaseCliLibDB400_gen.c
file_PaseCliLibDB400_c = ""
file_PaseCliLibDB400_c += file_pase_incl
file_PaseCliLibDB400_c += file_local_incl
file_PaseCliLibDB400_c += "" + "\n"
file_PaseCliLibDB400_c += "#define DFTCOLSIZE 18" + "\n"
file_PaseCliLibDB400_c += "#define SQL_MAXINTVAL_REASONABLE 131072" + "\n"
file_PaseCliLibDB400_c += "" + "\n"
file_PaseCliLibDB400_c += PaseCliLibDB400_c_symbol
file_PaseCliLibDB400_c += "" + "\n"
file_PaseCliLibDB400_c += non_utf_copy_in()
file_PaseCliLibDB400_c += non_utf_copy_in_free()
file_PaseCliLibDB400_c += non_utf_copy_out()
file_PaseCliLibDB400_c += non_utf_isconvert_ordinal();
file_PaseCliLibDB400_c += "" + "\n"
file_PaseCliLibDB400_c += PaseCliLibDB400_c_main
file_PaseCliLibDB400_c += "" + "\n"
with open("PaseCliLibDB400_gen.c", "w") as text_file:
text_file.write(file_PaseCliLibDB400_c)
# write PaseCliAsync_gen.c
file_PaseCliAsync_c = ""
file_PaseCliAsync_c += file_pase_incl
file_PaseCliAsync_c += file_local_incl
file_PaseCliAsync_c += "" + "\n"
file_PaseCliAsync_c += "" + "\n"
file_PaseCliAsync_c += PaseCliAsync_c_main
with open("PaseCliAsync_gen.c", "w") as text_file:
text_file.write(file_PaseCliAsync_c)
# write PaseCliDump_gen.c
file_PaseCliDump_c = ""
file_PaseCliDump_c += file_pase_incl
file_PaseCliDump_c += file_local_incl
file_PaseCliDump_c += '#include "PaseCliDev.h"' + "\n"
file_PaseCliDump_c += '#include "PaseCliPrintf.h"' + "\n"
file_PaseCliDump_c += "" + "\n"
file_PaseCliDump_c += "" + "\n"
file_PaseCliDump_c += PaseCliDump_c_main
with open("PaseCliDump_gen.c", "w") as text_file:
text_file.write(file_PaseCliDump_c)
# write PaseCliAsync.h
file_PaseCliAsync_h = ""
file_PaseCliAsync_h += '#ifndef _PASECLIASYNC_H' + "\n"
file_PaseCliAsync_h += '#define _PASECLIASYNC_H' + "\n"
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += file_pase_incl
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += '#ifdef __cplusplus' + "\n"
file_PaseCliAsync_h += 'extern "C" {' + "\n"
file_PaseCliAsync_h += '#endif' + "\n"
file_PaseCliAsync_h += '/* ===================================================' + "\n"
file_PaseCliAsync_h += ' * Using the driver' + "\n"
file_PaseCliAsync_h += ' * ===================================================' + "\n"
file_PaseCliAsync_h += ' */' + "\n"
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += "/* " + "\n"
file_PaseCliAsync_h += ' * SQL400Environment -- set the mode of driver' + "\n"
file_PaseCliAsync_h += ' * ' + "\n"
file_PaseCliAsync_h += ' * === UTF-8 mode, most popular AIX/PASE/Linux ===' + "\n"
file_PaseCliAsync_h += ' * SQLOverrideCCSID400(1208) -- UTF-8 mode, CLI normal/async direct ILE call' + "\n"
file_PaseCliAsync_h += ' * -->SQLExecDirect(Async)-->ILE_SQLExecDirect-->DB2' + "\n"
file_PaseCliAsync_h += ' * -->SQLExecDirectW(Async)-->ILE_SQLExecDirectW-->DB2' + "\n"
file_PaseCliAsync_h += ' * ' + "\n"
file_PaseCliAsync_h += ' * === UTF-8 mode, most popular Windows/Java ===' + "\n"
file_PaseCliAsync_h += ' * SQLOverrideCCSID400(1200) -- UTF-16 mode, CLI normal/async direct ILE call' + "\n"
file_PaseCliAsync_h += ' * -->SQLExecDirect(Async)-->ILE_SQLExecDirectW-->DB2' + "\n"
file_PaseCliAsync_h += ' * -->SQLExecDirectW(Async)-->ILE_SQLExecDirectW-->DB2' + "\n"
file_PaseCliAsync_h += ' * ' + "\n"
file_PaseCliAsync_h += ' * === PASE default (original libdb400.a) ===' + "\n"
file_PaseCliAsync_h += ' * SQLOverrideCCSID400(other) -- PASE ccsid, CLI API calls PASE libdb400.a' + "\n"
file_PaseCliAsync_h += ' * -->SQLExecDirect(Async)-->PASE libdb400.a(SQLExecDirect)-->DB2' + "\n"
file_PaseCliAsync_h += ' * -->SQLExecDirectW(Async)-->ILE_SQLExecDirectW-->DB2 (*)' + "\n"
file_PaseCliAsync_h += ' * ' + "\n"
file_PaseCliAsync_h += ' * PASE ccsid setting occurs before any other CLI operations' + "\n"
file_PaseCliAsync_h += ' * at the environment level. Therefore the driver mode is' + "\n"
file_PaseCliAsync_h += ' * established (restricted, if you choose). ' + "\n"
file_PaseCliAsync_h += ' * ' + "\n"
file_PaseCliAsync_h += ' * 1) non-Unicode interfaces (call old libdb400.a, messy stuff):' + "\n"
file_PaseCliAsync_h += ' * int ccsid = 819;' + "\n"
file_PaseCliAsync_h += ' * env attr SQL400_ATTR_PASE_CCSID &ccsid -- set pase ccsid' + "\n"
file_PaseCliAsync_h += ' * ' + "\n"
file_PaseCliAsync_h += ' * 2) UTF8 interfaces (call direct to ILE DB2):' + "\n"
file_PaseCliAsync_h += ' * int ccsid = 1208;' + "\n"
file_PaseCliAsync_h += ' * env attr SQL400_ATTR_PASE_CCSID &ccsid -- set pase ccsid' + "\n"
file_PaseCliAsync_h += ' * if ccsid == 1208:' + "\n"
file_PaseCliAsync_h += ' * env attr SQL_ATTR_UTF8 &true -- no conversion required by PASE' + "\n"
file_PaseCliAsync_h += ' * ' + "\n"
file_PaseCliAsync_h += ' * 3) UTF16 wide interfaces (call direct to ILE DB2):' + "\n"
file_PaseCliAsync_h += ' * **** NEVER set PASE_CCSID or ATTR_UTF8 in UTF-16 mode. ****' + "\n"
file_PaseCliAsync_h += ' * So, database exotic ebcdic column and PASE binds c type as WVARCHAR/WCHAR output is UTF16?' + "\n"
file_PaseCliAsync_h += ' * Yes, the database will do the conversion from EBCDIC to UTF16 for data bound as WVARCHAR/WCHAR.' + "\n"
file_PaseCliAsync_h += ' * not sure about DBCLOB -- I want to guess that is bound as UTF-16, not 100% sure.' + "\n"
file_PaseCliAsync_h += ' * ' + "\n"
file_PaseCliAsync_h += ' * IF your data not UTF-8 or UTF-16, interfaces to convert (experimental).' + "\n"
file_PaseCliAsync_h += ' * SQL400ToUtf8 -- use before passing to CLI normal interfaces' + "\n"
file_PaseCliAsync_h += ' * SQL400FromUtf8 -- use return output normal CLI (if needed)' + "\n"
file_PaseCliAsync_h += ' * SQL400ToUtf16 -- use before passing to CLI wide interfaces' + "\n"
file_PaseCliAsync_h += ' * SQL400FromUtf16 -- use return output wide CLI (if needed)' + "\n"
file_PaseCliAsync_h += ' * ' + "\n"
file_PaseCliAsync_h += " * A choice of exported APIs (SQLExecDirect one of many):" + "\n"
file_PaseCliAsync_h += " * " + "\n"
file_PaseCliAsync_h += ' * === CLI APIs UTF-8 or APIWs UTF-16 ===' + "\n"
file_PaseCliAsync_h += ' * === choose async and/or normal wait ===' + "\n"
file_PaseCliAsync_h += ' * SQLRETURN SQLExecDirect(..);' + "\n"
file_PaseCliAsync_h += ' * SQLRETURN SQLExecDirectW(..);' + "\n"
file_PaseCliAsync_h += ' * ' + "\n"
file_PaseCliAsync_h += ' * == callback or reap/join with async ===' + "\n"
file_PaseCliAsync_h += ' * pthread_t SQLExecDirectAsync(..);' + "\n"
file_PaseCliAsync_h += ' * pthread_t SQLExecDirectWAsync(..);' + "\n"
file_PaseCliAsync_h += ' * void SQLExecDirectCallback(SQLExecDirectStruct* );' + "\n"
file_PaseCliAsync_h += ' * SQLExecDirectStruct * SQLExecDirectJoin (pthread_t tid, SQLINTEGER flag);' + "\n"
file_PaseCliAsync_h += ' * void SQLExecDirectWCallback(SQLExecDirectWStruct* );' + "\n"
file_PaseCliAsync_h += ' * SQLExecDirectWStruct * SQLExecDirectWJoin (pthread_t tid, SQLINTEGER flag);' + "\n"
file_PaseCliAsync_h += ' * ' + "\n"
file_PaseCliAsync_h += ' * === bypass all, call PASE libdb400.a directly (not recommended) ===' + "\n"
file_PaseCliAsync_h += ' * SQLRETURN libdb400_SQLExecDirect(..);' + "\n"
file_PaseCliAsync_h += ' * SQLRETURN libdb400_SQLExecDirectW(..); (*)' + "\n"
file_PaseCliAsync_h += ' * ' + "\n"
file_PaseCliAsync_h += ' * === bypass all, call ILE directly (not recommended) ===' + "\n"
file_PaseCliAsync_h += ' * SQLRETURN ILE_SQLExecDirect(..);' + "\n"
file_PaseCliAsync_h += ' * SQLRETURN ILE_SQLExecDirectW(..);' + "\n"
file_PaseCliAsync_h += " * " + "\n"
file_PaseCliAsync_h += ' */' + "\n"
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += '/* ===================================================' + "\n"
file_PaseCliAsync_h += ' * CUSTOM interfaces' + "\n"
file_PaseCliAsync_h += ' * ===================================================' + "\n"
file_PaseCliAsync_h += ' */' + "\n"
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += '/* Use:' + "\n"
file_PaseCliAsync_h += ' * SQL400Environment ( ..., SQLPOINTER options )' + "\n"
file_PaseCliAsync_h += ' * SQL400Connect ( ..., SQLPOINTER options )' + "\n"
file_PaseCliAsync_h += ' * SQL400SetAttr ( ..., SQLPOINTER options )' + "\n"
file_PaseCliAsync_h += ' * CTOR:' + "\n"
file_PaseCliAsync_h += ' * SQL400AddAttr' + "\n"
file_PaseCliAsync_h += ' * Struct:' + "\n"
file_PaseCliAsync_h += ' * SQL400AttrStruct' + "\n"
file_PaseCliAsync_h += ' * e - EnvAttr' + "\n"
file_PaseCliAsync_h += ' * c - ConnectAttr' + "\n"
file_PaseCliAsync_h += ' * s - StmtAttr' + "\n"
file_PaseCliAsync_h += ' * o - StmtOption' + "\n"
file_PaseCliAsync_h += ' */' + "\n"
file_PaseCliAsync_h += '/* CLI hidden attributes */' + "\n"
file_PaseCliAsync_h += '#define SQL400_ATTR_PASE_CCSID 10011' + "\n"
file_PaseCliAsync_h += '#define SQL400_ATTR_CONN_JDBC 10201' + "\n"
file_PaseCliAsync_h += '/* stop or not on attribute failure */' + "\n"
file_PaseCliAsync_h += '#define SQL400_ONERR_CONT 1' + "\n"
file_PaseCliAsync_h += '#define SQL400_ONERR_STOP 2' + "\n"
file_PaseCliAsync_h += '/* normal attributes */' + "\n"
file_PaseCliAsync_h += '#define SQL400_FLAG_IMMED 0' + "\n"
file_PaseCliAsync_h += '/* post connect attributes */' + "\n"
file_PaseCliAsync_h += '#define SQL400_FLAG_POST_CONNECT 1' + "\n"
file_PaseCliAsync_h += '#define SQL400_ATTR_CONN_CHGCURLIB 424201' + "\n"
file_PaseCliAsync_h += '#define SQL400_ATTR_CONN_CHGLIBL 424202' + "\n"
file_PaseCliAsync_h += 'typedef struct SQL400AttrStruct {' + "\n"
file_PaseCliAsync_h += ' SQLINTEGER scope; /* - scope - SQL_HANDLE_ENV|DBC|SRTMT|DESC */' + "\n"
file_PaseCliAsync_h += ' SQLHANDLE hndl; /* ecso - hndl - CLI handle */' + "\n"
file_PaseCliAsync_h += ' SQLINTEGER attrib; /* ecso - attrib - CLI attribute */' + "\n"
file_PaseCliAsync_h += ' SQLPOINTER vParam; /* ecso - vParam - ptr to CLI value */' + "\n"
file_PaseCliAsync_h += ' SQLINTEGER inlen; /* ecs - inlen - len CLI value (string) */' + "\n"
file_PaseCliAsync_h += ' SQLINTEGER sqlrc; /* - sqlrc - sql return code */' + "\n"
file_PaseCliAsync_h += ' SQLINTEGER onerr; /* - onerr - SQL400_ONERR_xxx */' + "\n"
file_PaseCliAsync_h += ' SQLINTEGER flag; /* - flag - SQL400_FLAG_xxx */' + "\n"
file_PaseCliAsync_h += '} SQL400AttrStruct;' + "\n"
file_PaseCliAsync_h += '/* Use:' + "\n"
file_PaseCliAsync_h += ' * SQL400Execute( ..., SQLPOINTER parms, SQLPOINTER desc_parms)' + "\n"
file_PaseCliAsync_h += ' * SQL400Fetch (..., SQLPOINTER desc_cols)' + "\n"
file_PaseCliAsync_h += ' * CTOR:' + "\n"
file_PaseCliAsync_h += ' * SQL400Describe' + "\n"
file_PaseCliAsync_h += ' * SQL400AddCVar' + "\n"
file_PaseCliAsync_h += ' * Struct:' + "\n"
file_PaseCliAsync_h += ' * SQL400ParamStruct' + "\n"
file_PaseCliAsync_h += ' * SQL400DescribeStruct' + "\n"
file_PaseCliAsync_h += ' * p - SQLDescribeParam' + "\n"
file_PaseCliAsync_h += ' * c - SQLDescribeCol' + "\n"
file_PaseCliAsync_h += ' */' + "\n"
file_PaseCliAsync_h += '#define SQL400_DESC_PARM 0' + "\n"
file_PaseCliAsync_h += '#define SQL400_DESC_COL 1' + "\n"
file_PaseCliAsync_h += '#define SQL400_PARM_IO_FILE 42' + "\n"
file_PaseCliAsync_h += 'typedef struct SQL400ParamStruct {' + "\n"
file_PaseCliAsync_h += ' SQLSMALLINT icol; /* icol - param number (in) */' + "\n"
file_PaseCliAsync_h += ' SQLSMALLINT inOutType; /* inOutType - sql C in/out flag (in) */' + "\n"
file_PaseCliAsync_h += ' SQLSMALLINT pfSqlCType; /* pfSqlCType - sql C data type (in) */' + "\n"
file_PaseCliAsync_h += ' SQLPOINTER pfSqlCValue; /* pfSqlCValue - sql C ptr to data (out) */' + "\n"
file_PaseCliAsync_h += ' SQLINTEGER * indPtr; /* indPtr - sql strlen/ind (out) */' + "\n"
file_PaseCliAsync_h += '} SQL400ParamStruct;' + "\n"
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += 'typedef struct SQL400DescStruct {' + "\n"
file_PaseCliAsync_h += ' SQLSMALLINT itype; /* - itype - descr col/parm (out) */' + "\n"
file_PaseCliAsync_h += ' SQLSMALLINT icol; /* pc - icol - column number (in) */' + "\n"
file_PaseCliAsync_h += ' SQLCHAR * szColName; /* c - szColName - column name ptr (out) */' + "\n"
file_PaseCliAsync_h += ' SQLSMALLINT cbColNameMax; /* c - cbColNameMax - name max len (in) */' + "\n"
file_PaseCliAsync_h += ' SQLSMALLINT pcbColName; /* c - pcbColName - name size len (out) */' + "\n"
file_PaseCliAsync_h += ' SQLSMALLINT pfSqlType; /* pc - pfSqlType - sql data type (out) */' + "\n"
file_PaseCliAsync_h += ' SQLINTEGER pcbColDef; /* pc - pcbColDef - sql size column (out) */' + "\n"
file_PaseCliAsync_h += ' SQLSMALLINT pibScale; /* pc - pibScale - decimal digits (out) */' + "\n"
file_PaseCliAsync_h += ' SQLSMALLINT pfNullable; /* pc - pfNullable - null allowed (out) */' + "\n"
file_PaseCliAsync_h += ' SQLCHAR bfColName[1024]; /* c - bfColName - column name buf (out) */' + "\n"
file_PaseCliAsync_h += '} SQL400DescStruct;' + "\n"
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += "/* special SQL400 aggregate functions */" + "\n"
file_PaseCliAsync_h += "/* do common work for language driver */" + "\n"
file_PaseCliAsync_h += "/* composite calls to CLI also async */" + "\n"
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += PaseCliOnly400_h_proto
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += '/* ===================================================' + "\n"
file_PaseCliAsync_h += ' * NORMAL CLI interfaces' + "\n"
file_PaseCliAsync_h += ' * ===================================================' + "\n"
file_PaseCliAsync_h += ' */' + "\n"
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += "/* === sqlcli.h -- normal CLI interfaces (copy) === " + "\n"
file_PaseCliAsync_h += PaseCliAny_h_proto
file_PaseCliAsync_h += " * === sqlcli.h === */" + "\n"
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += '/* ===================================================' + "\n"
file_PaseCliAsync_h += ' * ASYNC CLI interfaces' + "\n"
file_PaseCliAsync_h += ' * ===================================================' + "\n"
file_PaseCliAsync_h += ' */' + "\n"
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += "/* choose either callback or join */" + "\n"
file_PaseCliAsync_h += "/* following structures returned */" + "\n"
file_PaseCliAsync_h += "/* caller must free return structure */" + "\n"
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += PaseCliAsync_h_struct + "\n"
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += "/* join async thread */" + "\n"
file_PaseCliAsync_h += "/* flag: */" + "\n"
file_PaseCliAsync_h += "/* SQL400_FLAG_JOIN_WAIT */" + "\n"
file_PaseCliAsync_h += "/* - block until complete */" + "\n"
file_PaseCliAsync_h += "/* SQL400_FLAG_JOIN_NO_WAIT */" + "\n"
file_PaseCliAsync_h += "/* - no block, NULL still executing */" + "\n"
file_PaseCliAsync_h += '#define SQL400_FLAG_JOIN_WAIT 0' + "\n"
file_PaseCliAsync_h += '#define SQL400_FLAG_JOIN_NO_WAIT 1' + "\n"
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += PaseCliAsync_h_proto_join
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += "/* start an async call to DB2 CLI */" + "\n"
file_PaseCliAsync_h += "/* choose either callback or join */" + "\n"
file_PaseCliAsync_h += "/* for results returned. */" + "\n"
file_PaseCliAsync_h += "/* sqlrc returned in structure. */" + "\n"
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += PaseCliAsync_h_proto_async
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += '/* ===================================================' + "\n"
file_PaseCliAsync_h += ' * ILE CLI interfaces' + "\n"
file_PaseCliAsync_h += ' * ===================================================' + "\n"
file_PaseCliAsync_h += ' */' + "\n"
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += PaseCliILE_h_proto
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += '/* ===================================================' + "\n"
file_PaseCliAsync_h += ' * LIBDB400.A CLI interfaces (PASE old CLI driver)' + "\n"
file_PaseCliAsync_h += ' * ===================================================' + "\n"
file_PaseCliAsync_h += ' */' + "\n"
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += PaseCliLibDB400_h_proto
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += '/* ===================================================' + "\n"
file_PaseCliAsync_h += ' * trace dump' + "\n"
file_PaseCliAsync_h += ' * ===================================================' + "\n"
file_PaseCliAsync_h += ' */' + "\n"
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += PaseCliDump_h_proto
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += '/* ===================================================' + "\n"
file_PaseCliAsync_h += ' * INTERNAL USE' + "\n"
file_PaseCliAsync_h += ' * ===================================================' + "\n"
file_PaseCliAsync_h += ' */' + "\n"
file_PaseCliAsync_h += "#ifndef SQL_ATTR_SERVERMODE_SUBSYSTEM" + "\n"
file_PaseCliAsync_h += "#define SQL_ATTR_SERVERMODE_SUBSYSTEM 10204" + "\n"
file_PaseCliAsync_h += "#endif" + "\n"
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += PaseCliCustom_h_proto
file_PaseCliAsync_h += "SQLRETURN custom_SQLSetEnvCCSID( SQLHANDLE env, int myccsid);" + "\n"
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += "" + "\n"
file_PaseCliAsync_h += '#ifdef __cplusplus ' + "\n"
file_PaseCliAsync_h += '}' + "\n"
file_PaseCliAsync_h += '#endif /* __cplusplus */' + "\n"
file_PaseCliAsync_h += '#endif /* _PASECLIASYNC_H */' + "\n"
with open("PaseCliAsync.h", "w") as text_file:
text_file.write(file_PaseCliAsync_h)
# write libdb400.exp
file_libdb400_exp = ""
file_libdb400_exp += "#!libdb400.a(shr.o)" + "\n"
file_libdb400_exp += "" + "\n"
file_libdb400_exp += "" + "\n"
file_libdb400_exp += libdb400_exp
file_libdb400_exp += "" + "\n"
file_libdb400_exp += "" + "\n"
file_libdb400_exp += "dev_dump" + "\n"
file_libdb400_exp += "dev_go" + "\n"
file_libdb400_exp += "printf_key" + "\n"
file_libdb400_exp += "printf_buffer" + "\n"
file_libdb400_exp += "printf_clear" + "\n"
file_libdb400_exp += "printf_format" + "\n"
file_libdb400_exp += "printf_hexdump" + "\n"
file_libdb400_exp += "printf_stack" + "\n"
file_libdb400_exp += "printf_script" + "\n"
file_libdb400_exp += "printf_script_include" + "\n"
file_libdb400_exp += "printf_script_exclude" + "\n"
file_libdb400_exp += "printf_script_clear" + "\n"
file_libdb400_exp += "printf_force_SIGQUIT" + "\n"
file_libdb400_exp += "printf_sqlrc_status" + "\n"
file_libdb400_exp += "printf_sqlrc_head_foot" + "\n"
file_libdb400_exp += "sprintf_format" + "\n"
file_libdb400_exp += "" + "\n"
file_libdb400_exp += "" + "\n"
with open("libdb400.exp", "w") as text_file:
text_file.write(file_libdb400_exp)
| pase_sql_cli_file = './gen_cli_template.c'
def parse_sizeme(st):
sz = '4'
if 'SMALL' in st:
sz = '2'
elif '*' in st:
sz = '4'
return sz
def parse_star(line):
v1 = ''
v2 = ''
v3 = ''
split1 = line.split('*')
if len(split1) > 1:
v1 = split1[0]
v2 = '*'
v3 = split1[1]
else:
split1 = line.split()
v1 = split1[0]
v2 = ''
v3 = split1[1]
return [v1.strip(), v2, v3.strip()]
def parse_method(line):
split1 = line.split('(')
func = split1[0]
split2 = split1[1].split(')')
argv = split2[0]
funcs = parse_star(func)
split3 = argv.split(',')
args = []
for arg in split3:
args.append(parse_star(arg))
return [funcs, args]
def pase_cli_async_c_main_sql_alloc_env(ile_or_custom_call, call_name, normal_db400_args):
c_main = ''
c_main += ' int myccsid = init_CCSID400(0);' + '\n'
c_main += ' init_lock();' + '\n'
c_main += ' switch(myccsid) {' + '\n'
c_main += ' case 1208: /* UTF-8 */' + '\n'
c_main += ' case 1200: /* UTF-16 */' + '\n'
c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' break;' + '\n'
c_main += ' default:' + '\n'
c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' break;' + '\n'
c_main += ' }' + '\n'
c_main += ' if (sqlrc == SQL_SUCCESS) {' + '\n'
c_main += ' init_table_ctor(*phenv, *phenv);' + '\n'
c_main += ' custom_SQLSetEnvCCSID(*phenv, myccsid);' + '\n'
c_main += ' }' + '\n'
c_main += ' init_unlock();' + '\n'
c_main += ' if (init_cli_trace()) {' + '\n'
c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n'
c_main += ' }' + '\n'
return c_main
def pase_cli_async_c_main_sql_alloc_connect(ile_or_custom_call, call_name, normal_db400_args):
c_main = ''
c_main += ' int myccsid = init_CCSID400(0);' + '\n'
c_main += ' init_lock();' + '\n'
c_main += ' switch(myccsid) {' + '\n'
c_main += ' case 1208: /* UTF-8 */' + '\n'
c_main += ' case 1200: /* UTF-16 */' + '\n'
c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' break;' + '\n'
c_main += ' default:' + '\n'
c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' break;' + '\n'
c_main += ' }' + '\n'
c_main += ' if (sqlrc == SQL_SUCCESS) {' + '\n'
c_main += ' init_table_ctor(*phdbc, *phdbc);' + '\n'
c_main += ' }' + '\n'
c_main += ' init_unlock();' + '\n'
c_main += ' if (init_cli_trace()) {' + '\n'
c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n'
c_main += ' }' + '\n'
return c_main
def pase_cli_async_c_main_sql_alloc_stmt(ile_or_custom_call, call_name, normal_db400_args):
c_main = ''
c_main += ' int myccsid = init_CCSID400(0);' + '\n'
c_main += ' init_lock();' + '\n'
c_main += ' switch(myccsid) {' + '\n'
c_main += ' case 1208: /* UTF-8 */' + '\n'
c_main += ' case 1200: /* UTF-16 */' + '\n'
c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' break;' + '\n'
c_main += ' default:' + '\n'
c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' break;' + '\n'
c_main += ' }' + '\n'
c_main += ' if (sqlrc == SQL_SUCCESS) {' + '\n'
c_main += ' init_table_ctor(*phstmt, hdbc);' + '\n'
c_main += ' }' + '\n'
c_main += ' init_unlock();' + '\n'
c_main += ' if (init_cli_trace()) {' + '\n'
c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n'
c_main += ' }' + '\n'
return c_main
def pase_cli_async_c_main_sql_alloc_handle(ile_or_custom_call, call_name, normal_db400_args):
c_main = ''
c_main += ' int myccsid = init_CCSID400(0);' + '\n'
c_main += ' init_lock();' + '\n'
c_main += ' switch(myccsid) {' + '\n'
c_main += ' case 1208: /* UTF-8 */' + '\n'
c_main += ' case 1200: /* UTF-16 */' + '\n'
c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' break;' + '\n'
c_main += ' default:' + '\n'
c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' break;' + '\n'
c_main += ' }' + '\n'
c_main += ' switch (htype) {' + '\n'
c_main += ' case SQL_HANDLE_ENV:' + '\n'
c_main += ' if (sqlrc == SQL_SUCCESS) {' + '\n'
c_main += ' init_table_ctor(*ohnd, *ohnd);' + '\n'
c_main += ' custom_SQLSetEnvCCSID(*ohnd, myccsid);' + '\n'
c_main += ' }' + '\n'
c_main += ' break;' + '\n'
c_main += ' case SQL_HANDLE_DBC:' + '\n'
c_main += ' if (sqlrc == SQL_SUCCESS) {' + '\n'
c_main += ' init_table_ctor(*ohnd, *ohnd);' + '\n'
c_main += ' }' + '\n'
c_main += ' break;' + '\n'
c_main += ' case SQL_HANDLE_STMT:' + '\n'
c_main += ' case SQL_HANDLE_DESC:' + '\n'
c_main += ' if (sqlrc == SQL_SUCCESS) {' + '\n'
c_main += ' init_table_ctor(*ohnd, ihnd);' + '\n'
c_main += ' }' + '\n'
c_main += ' break;' + '\n'
c_main += ' }' + '\n'
c_main += ' init_unlock();' + '\n'
c_main += ' if (init_cli_trace()) {' + '\n'
c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n'
c_main += ' }' + '\n'
return c_main
def pase_cli_async_c_main_sql_free_env(ile_or_custom_call, call_name, normal_db400_args):
c_main = ''
c_main += ' int myccsid = init_CCSID400(0);' + '\n'
c_main += ' init_lock();' + '\n'
c_main += ' switch(myccsid) {' + '\n'
c_main += ' case 1208: /* UTF-8 */' + '\n'
c_main += ' case 1200: /* UTF-16 */' + '\n'
c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' break;' + '\n'
c_main += ' default:' + '\n'
c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' break;' + '\n'
c_main += ' }' + '\n'
c_main += ' init_unlock();' + '\n'
c_main += ' if (init_cli_trace()) {' + '\n'
c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n'
c_main += ' }' + '\n'
return c_main
def pase_cli_async_c_main_sql_free_connect(ile_or_custom_call, call_name, normal_db400_args):
c_main = ''
c_main += ' int myccsid = init_CCSID400(0);' + '\n'
c_main += ' int active = init_table_hash_active(hdbc, 0);' + '\n'
c_main += ' /* persistent connect only close with SQL400pClose */' + '\n'
c_main += ' if (active) {' + '\n'
c_main += ' return SQL_ERROR;' + '\n'
c_main += ' }' + '\n'
c_main += ' init_lock();' + '\n'
c_main += ' switch(myccsid) {' + '\n'
c_main += ' case 1208: /* UTF-8 */' + '\n'
c_main += ' case 1200: /* UTF-16 */' + '\n'
c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' break;' + '\n'
c_main += ' default:' + '\n'
c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' break;' + '\n'
c_main += ' }' + '\n'
c_main += ' init_table_dtor(hdbc);' + '\n'
c_main += ' init_unlock();' + '\n'
c_main += ' if (init_cli_trace()) {' + '\n'
c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n'
c_main += ' }' + '\n'
return c_main
def pase_cli_async_c_main_sql_free_stmt(ile_or_custom_call, call_name, normal_db400_args):
c_main = ''
c_main += ' int myccsid = init_CCSID400(0);' + '\n'
c_main += ' init_lock();' + '\n'
c_main += ' switch(myccsid) {' + '\n'
c_main += ' case 1208: /* UTF-8 */' + '\n'
c_main += ' case 1200: /* UTF-16 */' + '\n'
c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' break;' + '\n'
c_main += ' default:' + '\n'
c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' break;' + '\n'
c_main += ' }' + '\n'
c_main += ' init_table_dtor(hstmt);' + '\n'
c_main += ' init_unlock();' + '\n'
c_main += ' if (init_cli_trace()) {' + '\n'
c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n'
c_main += ' }' + '\n'
return c_main
def pase_cli_async_c_main_sql_free_handle(ile_or_custom_call, call_name, normal_db400_args):
c_main = ''
c_main += ' int myccsid = init_CCSID400(0);' + '\n'
c_main += ' int persistent = init_table_hash_active(hndl, 0);' + '\n'
c_main += ' /* persistent connect only close with SQL400pClose */' + '\n'
c_main += ' switch (htype) {' + '\n'
c_main += ' case SQL_HANDLE_DBC:' + '\n'
c_main += ' if (persistent) {' + '\n'
c_main += ' return SQL_ERROR;' + '\n'
c_main += ' }' + '\n'
c_main += ' break;' + '\n'
c_main += ' default:' + '\n'
c_main += ' break;' + '\n'
c_main += ' }' + '\n'
c_main += ' init_lock();' + '\n'
c_main += ' switch(myccsid) {' + '\n'
c_main += ' case 1208: /* UTF-8 */' + '\n'
c_main += ' case 1200: /* UTF-16 */' + '\n'
c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' break;' + '\n'
c_main += ' default:' + '\n'
c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' break;' + '\n'
c_main += ' }' + '\n'
c_main += ' switch (htype) {' + '\n'
c_main += ' case SQL_HANDLE_ENV:' + '\n'
c_main += ' break;' + '\n'
c_main += ' default:' + '\n'
c_main += ' init_table_dtor(hndl);' + '\n'
c_main += ' break;' + '\n'
c_main += ' }' + '\n'
c_main += ' init_unlock();' + '\n'
c_main += ' if (init_cli_trace()) {' + '\n'
c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n'
c_main += ' }' + '\n'
return c_main
def sql_disconnect_check_persistent(hdbc_code, return_code, set_code):
c_main = ''
c_main += ' int persistent = init_table_hash_active(' + hdbc_code + ', 0);' + '\n'
c_main += ' /* persistent connect only close with SQL400pClose */' + '\n'
c_main += ' if (persistent) {' + '\n'
c_main += ' ' + set_code + '\n'
c_main += ' ' + return_code + '\n'
c_main += ' }' + '\n'
return c_main
def non_utf_copy_in():
c_main = ''
c_main += 'int non_utf_copy_in_hdbc(SQLHDBC\thdbc, SQLCHAR **tmp, SQLCHAR **src, SQLINTEGER srclen, SQLINTEGER maxlen) {' + '\n'
c_main += ' SQLRETURN sqlrc1 = SQL_SUCCESS;' + '\n'
c_main += ' int inccsid = init_CCSID400(0);' + '\n'
c_main += ' int outccsid = init_job_CCSID400();' + '\n'
c_main += ' SQLCHAR * inparm = *src;' + '\n'
c_main += ' SQLINTEGER inlen = srclen;' + '\n'
c_main += ' SQLCHAR * outparm = (SQLCHAR *) NULL;' + '\n'
c_main += ' SQLINTEGER outlen = 0;' + '\n'
c_main += ' if (inparm) {' + '\n'
c_main += ' if (srclen == SQL_NTS) {' + '\n'
c_main += ' inlen = strlen(inparm);' + '\n'
c_main += ' }' + '\n'
c_main += ' outlen = maxlen;' + '\n'
c_main += ' outparm = (SQLCHAR *) malloc(outlen);' + '\n'
c_main += ' memset(outparm,0,outlen);' + '\n'
c_main += ' sqlrc1 = SQL400IgnoreNullAnyToAny(hdbc, inparm, inlen, outparm, outlen, inccsid, outccsid);' + '\n'
c_main += ' outlen = strlen(outparm);' + '\n'
c_main += ' }' + '\n'
c_main += ' *tmp = *src;' + '\n'
c_main += ' if (*src) {' + '\n'
c_main += ' *src = outparm;' + '\n'
c_main += ' }' + '\n'
c_main += ' return outlen;' + '\n'
c_main += '}' + '\n'
c_main += 'int non_utf_copy_in_hstmt(SQLHSTMT hstmt, SQLCHAR **tmp, SQLCHAR **src, SQLINTEGER srclen, SQLINTEGER maxlen) {' + '\n'
c_main += ' SQLHDBC hdbc = init_table_stmt_2_conn(hstmt);' + '\n'
c_main += ' return non_utf_copy_in_hdbc(hdbc, tmp, src, srclen, maxlen);' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_copy_in_free():
c_main = ''
c_main += 'void non_utf_copy_in_free(SQLCHAR **tmp, SQLCHAR **src) {' + '\n'
c_main += ' char * trash = *src;' + '\n'
c_main += ' *src = *tmp;' + '\n'
c_main += ' if (trash) {' + '\n'
c_main += ' free(trash);' + '\n'
c_main += ' *tmp = NULL;' + '\n'
c_main += ' }' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_copy_out():
c_main = ''
c_main += 'int non_utf_copy_out_hdbc(SQLHDBC\thdbc, SQLRETURN sqlrc, SQLCHAR *src, SQLINTEGER srclen) {' + '\n'
c_main += ' SQLRETURN sqlrc1 = SQL_SUCCESS;' + '\n'
c_main += ' int inccsid = init_CCSID400(0);' + '\n'
c_main += ' int outccsid = init_job_CCSID400();' + '\n'
c_main += ' SQLCHAR * inparm = src;' + '\n'
c_main += ' SQLINTEGER inlen = srclen;' + '\n'
c_main += ' SQLCHAR * outparm = (SQLCHAR *) NULL;' + '\n'
c_main += ' SQLINTEGER outlen = 0;' + '\n'
c_main += ' if (inparm && (inlen != SQL_NULL_DATA) && (sqlrc == SQL_SUCCESS || sqlrc == SQL_SUCCESS_WITH_INFO)) {' + '\n'
c_main += ' outlen = inlen + 1;' + '\n'
c_main += ' outparm = (SQLCHAR *) malloc(outlen);' + '\n'
c_main += ' memset(outparm,0,outlen);' + '\n'
c_main += ' sqlrc1 = SQL400IgnoreNullAnyFromAny(hdbc, inparm, inlen, outparm, outlen, inccsid, outccsid);' + '\n'
c_main += ' outlen = strlen(outparm);' + '\n'
c_main += ' memcpy(inparm,outparm,inlen);' + '\n'
c_main += ' free(outparm);' + '\n'
c_main += ' }' + '\n'
c_main += ' return outlen;' + '\n'
c_main += '}' + '\n'
c_main += 'int non_utf_copy_out_hstmt(SQLHSTMT hstmt, SQLRETURN sqlrc, SQLCHAR *src, SQLINTEGER srclen) {' + '\n'
c_main += ' SQLHDBC hdbc = init_table_stmt_2_conn(hstmt);' + '\n'
c_main += ' return non_utf_copy_out_hdbc(hdbc, sqlrc, src, srclen);' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_isconvert_ordinal():
c_main = ''
c_main += 'int non_utf_isconvert_ordinal(SQLINTEGER ord) {' + '\n'
c_main += ' int convert = 0;' + '\n'
c_main += ' switch(ord) {' + '\n'
c_main += ' case SQL_ATTR_DBC_DEFAULT_LIB:' + ' \n'
c_main += ' case SQL_ATTR_SAVEPOINT_NAME:' + ' \n'
c_main += ' case SQL_ATTR_INFO_ACCTSTR:' + ' \n'
c_main += ' case SQL_ATTR_INFO_APPLNAME:' + ' \n'
c_main += ' case SQL_ATTR_INFO_PROGRAMID:' + ' \n'
c_main += ' case SQL_ATTR_INFO_USERID:' + ' \n'
c_main += ' case SQL_ATTR_INFO_WRKSTNNAME:' + ' \n'
c_main += ' case SQL_ATTR_SERVERMODE_SUBSYSTEM:' + ' \n'
c_main += ' case SQL_DBMS_NAME:' + ' \n'
c_main += ' case SQL_DBMS_VER:' + ' \n'
c_main += ' case SQL_PROCEDURES:' + ' \n'
c_main += ' case SQL_DATA_SOURCE_NAME:' + ' \n'
c_main += ' case SQL_COLUMN_ALIAS:' + ' \n'
c_main += ' case SQL_DATA_SOURCE_READ_ONLY:' + ' \n'
c_main += ' case SQL_MULTIPLE_ACTIVE_TXN:' + ' \n'
c_main += ' case SQL_DRIVER_NAME:' + ' \n'
c_main += ' case SQL_IDENTIFIER_QUOTE_CHAR:' + ' \n'
c_main += ' case SQL_PROCEDURE_TERM:' + ' \n'
c_main += ' case SQL_QUALIFIER_TERM:' + ' \n'
c_main += ' case SQL_QUALIFIER_NAME_SEPARATOR:' + ' \n'
c_main += ' case SQL_OWNER_TERM:' + ' \n'
c_main += ' case SQL_DRIVER_ODBC_VER:' + ' \n'
c_main += ' case SQL_ORDER_BY_COLUMNS_IN_SELECT:' + ' \n'
c_main += ' case SQL_SEARCH_PATTERN_ESCAPE:' + ' \n'
c_main += ' case SQL_OUTER_JOINS:' + ' \n'
c_main += ' case SQL_LIKE_ESCAPE_CLAUSE:' + ' \n'
c_main += ' case SQL_CATALOG_NAME:' + ' \n'
c_main += ' case SQL_DESCRIBE_PARAMETER:' + ' \n'
c_main += ' convert = 1;' + '\n'
c_main += ' break;' + '\n'
c_main += ' }' + '\n'
c_main += ' return convert;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_col_attributes(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER outsz = 0;' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' if (fDescType == SQL_DESC_NAME) {' + '\n'
c_main += ' outsz = non_utf_copy_out_hstmt(hstmt, sqlrc, (SQLCHAR *)rgbDesc, (SQLINTEGER)cbDescMax);' + '\n'
c_main += ' if (pcbDesc) *pcbDesc = outsz;' + '\n'
c_main += ' }' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_column_privileges(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n'
c_main += ' SQLCHAR * tmp1 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp2 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp3 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp4 = NULL;' + '\n'
c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)cbTableQualifier, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)cbTableOwner, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)cbTableName, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbColumnName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName, (SQLINTEGER)cbColumnName, (SQLINTEGER)maxsz);' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName);' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_columns(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n'
c_main += ' SQLCHAR * tmp1 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp2 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp3 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp4 = NULL;' + '\n'
c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)cbTableQualifier, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)cbTableOwner, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)cbTableName, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbColumnName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName, (SQLINTEGER)cbColumnName, (SQLINTEGER)maxsz);' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName);' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_connect(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n'
c_main += ' SQLCHAR * tmp1 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp2 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp3 = NULL;' + '\n'
c_main += ' cbDSN = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp1, (SQLCHAR **)&szDSN, (SQLINTEGER)cbDSN, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbUID = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp2, (SQLCHAR **)&szUID, (SQLINTEGER)cbUID, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbAuthStr = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp3, (SQLCHAR **)&szAuthStr, (SQLINTEGER)cbAuthStr, (SQLINTEGER)maxsz);' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szDSN);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szUID);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szAuthStr);' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_data_sources(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER tmpsz = 0;' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' tmpsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szDSN, (SQLINTEGER)cbDSNMax);' + '\n'
c_main += ' tmpsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szDescription, (SQLINTEGER)cbDescriptionMax);' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_describe_col(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER outsz = 0;' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szColName, (SQLINTEGER)cbColNameMax);' + '\n'
c_main += ' if (pcbColName) *pcbColName = outsz;' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_driver_connect(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER outsz = 0;' + '\n'
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n'
c_main += ' SQLCHAR * tmp1 = NULL;' + '\n'
c_main += ' cbConnStrin = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp1, (SQLCHAR **)&szConnStrIn, (SQLINTEGER)cbConnStrin, (SQLINTEGER)maxsz);' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szConnStrIn);' + '\n'
c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szConnStrOut, (SQLINTEGER)cbConnStrOutMax);' + '\n'
c_main += ' if (pcbConnStrOut) *pcbConnStrOut = outsz;' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_error(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER outsz = 0;' + '\n'
c_main += ' SQLINTEGER maxsz = SQL_SQLSTATE_SIZE + 1;' + '\n'
c_main += ' SQLINTEGER tmpsz = 0;' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' tmpsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szSqlState, (SQLINTEGER)maxsz);' + '\n'
c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szErrorMsg, (SQLINTEGER)cbErrorMsgMax);' + '\n'
c_main += ' if (pcbErrorMsg) *pcbErrorMsg = outsz;' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_exec_direct(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + '\n'
c_main += ' SQLCHAR * tmp1 = NULL;' + '\n'
c_main += ' cbSqlStr = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStr, (SQLINTEGER)cbSqlStr, (SQLINTEGER)maxsz);' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStr);' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_foreign_keys(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n'
c_main += ' SQLCHAR * tmp1 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp2 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp3 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp4 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp5 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp6 = NULL;' + '\n'
c_main += ' cbPkTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szPkTableQualifier, (SQLINTEGER)cbPkTableQualifier, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbPkTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szPkTableOwner, (SQLINTEGER)cbPkTableOwner, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbPkTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szPkTableName, (SQLINTEGER)cbPkTableName, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbFkTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp4, (SQLCHAR **)&szFkTableQualifier, (SQLINTEGER)cbFkTableQualifier, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbFkTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp5, (SQLCHAR **)&szFkTableOwner, (SQLINTEGER)cbFkTableOwner, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbFkTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp6, (SQLCHAR **)&szFkTableName, (SQLINTEGER)cbFkTableName, (SQLINTEGER)maxsz);' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szPkTableQualifier);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szPkTableOwner);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szPkTableName);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp4, (SQLCHAR **)&szFkTableQualifier);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp5, (SQLCHAR **)&szFkTableOwner);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp6, (SQLCHAR **)&szFkTableName);' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_get_connect_attr(call_name, normal_db400_args):
c_main = ''
c_main += ' int isconvert = non_utf_isconvert_ordinal(attr);' + '\n'
c_main += ' SQLINTEGER outsz = 0;' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' if (isconvert) {' + '\n'
c_main += ' outsz = non_utf_copy_out_hdbc(hdbc, sqlrc, (SQLCHAR *)oval, (SQLINTEGER)ilen);' + '\n'
c_main += ' if (olen) *olen = outsz;' + '\n'
c_main += ' }' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_get_connect_option(call_name, normal_db400_args):
c_main = ''
c_main += ' int isconvert = non_utf_isconvert_ordinal(iopt);' + '\n'
c_main += ' SQLINTEGER maxsz = DFTCOLSIZE;' + '\n'
c_main += ' SQLINTEGER tmpsz = 0;' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' if (isconvert) {' + '\n'
c_main += ' tmpsz = non_utf_copy_out_hdbc(hdbc, sqlrc, (SQLCHAR *)oval, (SQLINTEGER)maxsz);' + '\n'
c_main += ' }' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_get_cursor_name(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER outsz = 0;' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szCursor, (SQLINTEGER)cbCursorMax);' + '\n'
c_main += ' if (pcbCursor) *pcbCursor = outsz;' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_get_desc_field(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER outsz = 0;' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' if (fieldID == SQL_DESC_NAME) {' + '\n'
c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)fValue, (SQLINTEGER)fLength);' + '\n'
c_main += ' if (stLength) *stLength = outsz;' + '\n'
c_main += ' }' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_get_desc_rec(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER outsz = 0;' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)fname, (SQLINTEGER)bufLen);' + '\n'
c_main += ' if (sLength) *sLength = outsz;' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_get_diag_field(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER outsz = 0;' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' if (diagID == SQL_DIAG_SQLSTATE || diagID == SQL_DIAG_MESSAGE_TEXT || diagID == SQL_DIAG_SERVER_NAME) {' + '\n'
c_main += ' if (hType == SQL_HANDLE_DBC) {' + '\n'
c_main += ' outsz = non_utf_copy_out_hdbc(hndl, sqlrc, (SQLCHAR *)dValue, (SQLINTEGER)bLength);' + '\n'
c_main += ' } else {' + '\n'
c_main += ' outsz = non_utf_copy_out_hstmt(hndl, sqlrc, (SQLCHAR *)dValue, (SQLINTEGER)bLength);' + '\n'
c_main += ' }' + '\n'
c_main += ' if (sLength) *sLength = outsz;' + '\n'
c_main += ' }' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_get_diag_rec(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER outsz = 0;' + '\n'
c_main += ' SQLINTEGER maxsz = SQL_SQLSTATE_SIZE + 1;' + '\n'
c_main += ' SQLINTEGER tmpsz = 0;' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' if (hType == SQL_HANDLE_DBC) {' + '\n'
c_main += ' tmpsz = non_utf_copy_out_hdbc(hndl, sqlrc, (SQLCHAR *)SQLstate, (SQLINTEGER)maxsz);' + '\n'
c_main += ' outsz = non_utf_copy_out_hdbc(hndl, sqlrc, (SQLCHAR *)msgText, (SQLINTEGER)bLength);' + '\n'
c_main += ' } else {' + '\n'
c_main += ' tmpsz = non_utf_copy_out_hstmt(hndl, sqlrc, (SQLCHAR *)SQLstate, (SQLINTEGER)maxsz);' + '\n'
c_main += ' outsz = non_utf_copy_out_hstmt(hndl, sqlrc, (SQLCHAR *)msgText, (SQLINTEGER)bLength);' + '\n'
c_main += ' }' + '\n'
c_main += ' if (SLength) *SLength = outsz;' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_get_env_attr(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER outsz = 0;' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' if (fAttribute == SQL_ATTR_DEFAULT_LIB || fAttribute == SQL_ATTR_ESCAPE_CHAR) {' + '\n'
c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)pParam, (SQLINTEGER)cbParamMax);' + '\n'
c_main += ' }' + '\n'
c_main += ' if (pcbParam) *pcbParam = outsz;' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_get_info(call_name, normal_db400_args):
c_main = ''
c_main += ' int isconvert = non_utf_isconvert_ordinal(fInfoType);' + '\n'
c_main += ' SQLINTEGER outsz = 0;' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' if (isconvert) {' + '\n'
c_main += ' outsz = non_utf_copy_out_hdbc(hdbc, sqlrc, (SQLCHAR *)rgbInfoValue, (SQLINTEGER)cbInfoValueMax);' + '\n'
c_main += ' if (pcbInfoValue) *pcbInfoValue = outsz;' + '\n'
c_main += ' }' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_get_position(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + '\n'
c_main += ' SQLCHAR * tmp1 = NULL;' + '\n'
c_main += ' srchLiteralLen = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&srchLiteral, (SQLINTEGER)srchLiteralLen, (SQLINTEGER)maxsz);' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&srchLiteral);' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_native_sql(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER outsz = 0;' + '\n'
c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + '\n'
c_main += ' SQLCHAR * tmp1 = NULL;' + '\n'
c_main += ' cbSqlStrIn = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStrIn, (SQLINTEGER)cbSqlStrIn, (SQLINTEGER)maxsz);' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStrIn);' + '\n'
c_main += ' outsz = non_utf_copy_out_hdbc(hdbc, sqlrc, (SQLCHAR *)szSqlStr, (SQLINTEGER)cbSqlStrMax);' + '\n'
c_main += ' if (pcbSqlStr) *pcbSqlStr = outsz;' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_param_data(call_name, normal_db400_args):
c_main = ''
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_prepare(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + '\n'
c_main += ' SQLCHAR * tmp1 = NULL;' + '\n'
c_main += ' cbSqlStr = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStr, (SQLINTEGER)cbSqlStr, (SQLINTEGER)maxsz);' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStr);' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_primary_keys(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n'
c_main += ' SQLCHAR * tmp1 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp2 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp3 = NULL;' + '\n'
c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)cbTableQualifier, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)cbTableOwner, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)cbTableName, (SQLINTEGER)maxsz);' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_procedure_columns(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n'
c_main += ' SQLCHAR * tmp1 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp2 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp3 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp4 = NULL;' + '\n'
c_main += ' cbProcQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szProcQualifier, (SQLINTEGER)cbProcQualifier, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbProcOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szProcOwner, (SQLINTEGER)cbProcOwner, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbProcName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szProcName, (SQLINTEGER)cbProcName, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbColumnName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName, (SQLINTEGER)cbColumnName, (SQLINTEGER)maxsz);' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szProcQualifier);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szProcOwner);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szProcName);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName);' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_procedures(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n'
c_main += ' SQLCHAR * tmp1 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp2 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp3 = NULL;' + '\n'
c_main += ' cbProcQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szProcQualifier, (SQLINTEGER)cbProcQualifier, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbProcOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szProcOwner, (SQLINTEGER)cbProcOwner, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbProcName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szProcName, (SQLINTEGER)cbProcName, (SQLINTEGER)maxsz);' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szProcQualifier);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szProcOwner);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szProcName);' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_set_connect_attr(call_name, normal_db400_args):
c_main = ''
c_main += ' int isconvert = non_utf_isconvert_ordinal(attrib);' + '\n'
c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + '\n'
c_main += ' SQLCHAR * tmp1 = NULL;' + '\n'
c_main += ' if (isconvert) {' + '\n'
c_main += ' inlen = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp1, (SQLCHAR **)&vParam, (SQLINTEGER)inlen, (SQLINTEGER)maxsz);' + '\n'
c_main += ' }' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' if (isconvert) {' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&vParam);' + '\n'
c_main += ' }' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_set_connect_option(call_name, normal_db400_args):
c_main = ''
c_main += ' int isconvert = non_utf_isconvert_ordinal(fOption);' + '\n'
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n'
c_main += ' SQLINTEGER tmpsz = 0;' + '\n'
c_main += ' SQLCHAR * tmp1 = NULL;' + '\n'
c_main += ' if (isconvert) {' + '\n'
c_main += ' tmpsz = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp1, (SQLCHAR **)&vParam, (SQLINTEGER)SQL_NTS, (SQLINTEGER)maxsz);' + '\n'
c_main += ' }' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' if (isconvert) {' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&vParam);' + '\n'
c_main += ' }' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_set_cursor_name(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n'
c_main += ' SQLCHAR * tmp1 = NULL;' + '\n'
c_main += ' cbCursor = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szCursor, (SQLINTEGER)cbCursor, (SQLINTEGER)maxsz);' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szCursor);' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_set_env_attr(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + '\n'
c_main += ' SQLCHAR * tmp1 = NULL;' + '\n'
c_main += ' if (fAttribute == SQL_ATTR_DBC_DEFAULT_LIB || fAttribute == SQL_ATTR_SAVEPOINT_NAME) {' + '\n'
c_main += ' cbParam = non_utf_copy_in_hdbc(0, (SQLCHAR **)&tmp1, (SQLCHAR **)&pParam, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + '\n'
c_main += ' }' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' if (fAttribute == SQL_ATTR_DBC_DEFAULT_LIB || fAttribute == SQL_ATTR_SAVEPOINT_NAME) {' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&pParam);' + '\n'
c_main += ' }' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_special_columns(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n'
c_main += ' SQLCHAR * tmp1 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp2 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp3 = NULL;' + '\n'
c_main += ' cbTableQual = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQual, (SQLINTEGER)cbTableQual, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)cbTableOwner, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)cbTableName, (SQLINTEGER)maxsz);' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQual);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_statistics(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n'
c_main += ' SQLCHAR * tmp1 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp2 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp3 = NULL;' + '\n'
c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)cbTableQualifier, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)cbTableOwner, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)cbTableName, (SQLINTEGER)maxsz);' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_table_privileges(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n'
c_main += ' SQLCHAR * tmp1 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp2 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp3 = NULL;' + '\n'
c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def non_utf_sql_tables(call_name, normal_db400_args):
c_main = ''
c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n'
c_main += ' SQLCHAR * tmp1 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp2 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp3 = NULL;' + '\n'
c_main += ' SQLCHAR * tmp4 = NULL;' + '\n'
c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + '\n'
c_main += ' cbTableType = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp4, (SQLCHAR **)&szTableType, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + '\n'
c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + '\n'
c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp4, (SQLCHAR **)&szTableType);' + '\n'
c_main += ' return sqlrc;' + '\n'
c_main += '}' + '\n'
return c_main
def ile_sql_param_data_copy_var():
c_main = ''
c_main += ' /* returnPtr - API returns ILE SP pointer buffer (alias of PASE ptr) */ ' + '\n'
c_main += ' char returnBuffer[ sizeof(ILEpointer ) + 16 ];' + '\n'
c_main += ' ILEpointer\t*returnPtr = (ILEpointer *)ROUND_QUAD(returnBuffer);' + '\n'
return c_main
def ile_sql_param_data_copy_in():
c_main = ''
c_main += ' /* returnPtr - ILE SP pointer buffer return area */ ' + '\n'
c_main += ' if (Value) {' + '\n'
c_main += ' arglist->Value.s.addr = (ulong) returnPtr;' + '\n'
c_main += ' }' + '\n'
return c_main
def ile_sql_param_data_copy_out():
c_main = ''
c_main += ' /* returnPtr - ILE SP to PASE pointer */ ' + '\n'
c_main += ' if (Value) {' + '\n'
c_main += ' if (arglist->base.result.s_int32.r_int32 == SQL_NEED_DATA) {' + '\n'
c_main += ' *Value = _CVTSPP(returnPtr);' + '\n'
c_main += ' }' + '\n'
c_main += ' }' + '\n'
return c_main
def ile_sql_get_desc_field_copy_var():
c_main = ''
c_main += ' /* returnPtr - API returns ILE SP pointer buffer (alias of PASE ptr)' + '\n'
c_main += ' * Return ILE SP likely outside PASE mapable addr space.' + '\n'
c_main += ' * However, _CVTSPP is safe. The result is zero (null)' + '\n'
c_main += ' * if the input is a 16-byte null pointer or a tagged space pointer ' + '\n'
c_main += ' * that does not contain the teraspace address' + '\n'
c_main += ' * equivalent of some valid IBM PASE for i memory address.' + '\n'
c_main += ' * (I suspect options never used in years of PASE.' + '\n'
c_main += ' * Rochester CLI team was notified).' + '\n'
c_main += ' */' + '\n'
c_main += ' char returnBuffer[ sizeof(ILEpointer ) + 16 ];' + '\n'
c_main += ' ILEpointer\t*returnPtr = (ILEpointer *)ROUND_QUAD(returnBuffer);' + '\n'
return c_main
def ile_sql_get_desc_field_copy_in():
c_main = ''
c_main += ' /* returnPtr - ILE SP pointer buffer return area */ ' + '\n'
c_main += ' if (fValue) {' + '\n'
c_main += ' if (fieldID == SQL_DESC_DATA_PTR' + '\n'
c_main += ' || fieldID == SQL_DESC_LENGTH_PTR' + '\n'
c_main += ' || fieldID == SQL_DESC_INDICATOR_PTR)' + '\n'
c_main += ' {' + '\n'
c_main += ' arglist->fValue.s.addr = (ulong) returnPtr;' + '\n'
c_main += ' }' + '\n'
c_main += ' }' + '\n'
return c_main
def ile_sql_get_desc_field_copy_out():
c_main = ''
c_main += ' /* returnPtr - ILE SP to PASE pointer */ ' + '\n'
c_main += ' if (fValue) {' + '\n'
c_main += ' if (fieldID == SQL_DESC_DATA_PTR' + '\n'
c_main += ' || fieldID == SQL_DESC_LENGTH_PTR' + '\n'
c_main += ' || fieldID == SQL_DESC_INDICATOR_PTR)' + '\n'
c_main += ' {' + '\n'
c_main += ' *((void **)fValue) = _CVTSPP(returnPtr);' + '\n'
c_main += ' }' + '\n'
c_main += ' }' + '\n'
return c_main
pre = open(PaseSqlCli_file, 'r')
ile_wide_api = {'nothing': 'nothing'}
for line in pre:
if 'SQLRETURN SQL' in line:
lesss = line.split('(')
parts = lesss[0].split(' ')
funcs = parts[1]
if '400' in funcs:
continue
if 'W' in funcs:
line_no_w = funcs.split('W')
assoc_name = line_no_W[0]
ile_wide_api[assoc_name] = funcs
f = open(PaseSqlCli_file, 'r')
g = False
c400 = True
c400_ccsid = False
c400_not_wide = True
ile_or_custom_call = ''
ile_or_libdb400_call = ''
line_func = ''
libdb400_exp = ''
pase_cli_lib_db400_h_proto = ''
pase_cli_lib_db400_c_symbol = ''
pase_cli_lib_db400_c_main = ''
pase_cli_async_h_struct = ''
pase_cli_async_h_proto_async = ''
pase_cli_async_h_proto_join = ''
pase_cli_async_c_main = ''
pase_cli_any_h_proto = ''
pase_cli_only400_h_proto = ''
pase_cli_ile_h_proto = ''
pase_cli_ile_c_symbol = ''
pase_cli_custom_h_proto = ''
pase_cli_ile_h_struct = ''
pase_cli_ile_c_main = ''
pase_cli_dump_h_proto = ''
pase_cli_dump_c_main = ''
for line in f:
if 'SQLRETURN SQL' in line:
g = True
line_func = ''
if g:
line_no_comment = line.split('/')
split0 = line_no_comment[0]
line_func += split0
if not ')' in split0:
continue
else:
g = False
else:
continue
parts = parse_method(line_func)
funcs = parts[0]
args = parts[1]
call_retv = funcs[0] + funcs[1]
call_name = funcs[2]
struct_name = call_name + 'Struct'
struct_ile_name = call_name + 'IleCallStruct'
struct_ile_sig = call_name + 'IleSigStruct'
struct_ile_flag = call_name + 'Loaded'
struct_ile_buf = call_name + 'Buf'
struct_ile_ptr = call_name + 'Ptr'
c400_not_wide = True
c400_ccsid = False
c400 = True
ile_or_custom_call = 'custom_'
ile_or_libdb400_call = 'libdb400_'
if 'SQLOverrideCCSID400' in call_name:
c400_ccsid = True
if 'SQL400' in call_name:
c400 = False
if c400:
ile_or_custom_call = 'ILE_'
if 'W' in call_name:
ile_or_libdb400_call = 'ILE_'
c400_not_wide = False
idx = 0
comma = ','
semi = ';'
argtype1st = ''
argname1st = ''
normal_call_types = ''
normal_call_args = ''
normal_db400_args = ''
async_struct_types = ' SQLRETURN sqlrc;'
async_call_args = ''
async_db400_args = ''
async_copyin_args = ''
ile_struct_sigs = ''
ile_struct_types = 'ILEarglist_base base;'
ile_copyin_args = ''
dump_args = ''
dump_sigs = ''
for arg in args:
idx += 1
if idx == len(args):
comma = ''
argfull = ' '.join(arg)
argsig = arg[0] + arg[1]
argname = arg[2]
if idx == 1:
argtype1st = arg[0]
argname1st = arg[2]
sigile = ''
ilefull = argfull
if arg[1] == '*':
sigile = 'ARG_MEMPTR'
ilefull = 'ILEpointer' + ' ' + arg[2]
elif arg[0] == 'PTR':
sigile = 'ARG_MEMPTR'
ilefull = 'ILEpointer' + ' ' + arg[2]
elif arg[0] == 'SQLHWND':
sigile = 'ARG_MEMPTR'
ilefull = 'ILEpointer' + ' ' + arg[2]
elif arg[0] == 'SQLPOINTER':
sigile = 'ARG_MEMPTR'
ilefull = 'ILEpointer' + ' ' + arg[2]
elif arg[0] == 'SQLCHAR':
sigile = 'ARG_UINT8'
elif arg[0] == 'SQLWCHAR':
sigile = 'ARG_UINT8'
elif arg[0] == 'SQLSMALLINT':
sigile = 'ARG_INT16'
elif arg[0] == 'SQLUSMALLINT':
sigile = 'ARG_UINT16'
elif arg[0] == 'SQLSMALLINT':
sigile = 'ARG_INT16'
elif arg[0] == 'SQLINTEGER':
sigile = 'ARG_INT32'
elif arg[0] == 'SQLUINTEGER':
sigile = 'ARG_UINT32'
elif arg[0] == 'SQLDOUBLE':
sigile = 'ARG_FLOAT64'
elif arg[0] == 'SQLREAL':
sigile = 'ARG_FLOAT32'
elif arg[0] == 'HENV':
sigile = 'ARG_INT32'
elif arg[0] == 'HDBC':
sigile = 'ARG_INT32'
elif arg[0] == 'HSTMT':
sigile = 'ARG_INT32'
elif arg[0] == 'HDESC':
sigile = 'ARG_INT32'
elif arg[0] == 'SQLHANDLE':
sigile = 'ARG_INT32'
elif arg[0] == 'SQLHENV':
sigile = 'ARG_INT32'
elif arg[0] == 'SQLHDBC':
sigile = 'ARG_INT32'
elif arg[0] == 'SQLHSTMT':
sigile = 'ARG_INT32'
elif arg[0] == 'SQLHDESC':
sigile = 'ARG_INT32'
elif arg[0] == 'RETCODE':
sigile = 'ARG_INT32'
elif arg[0] == 'SQLRETURN':
sigile = 'ARG_INT32'
elif arg[0] == 'SFLOAT':
sigile = 'ARG_FLOAT32'
normal_call_args += ' ' + argfull + comma
normal_db400_args += ' ' + argname + comma
normal_call_types += ' ' + argsig + comma
dump_args += ' ' + argname
dump_sigs += ' ' + argsig
ile_struct_types += ' ' + ilefull + semi
ile_struct_sigs += ' ' + sigile + comma
if sigile == 'ARG_MEMPTR':
ile_copyin_args += ' arglist->' + argname + '.s.addr = (ulong) ' + argname + ';' + '\n'
else:
ile_copyin_args += ' arglist->' + argname + ' = (' + argsig + ') ' + argname + ';' + '\n'
async_struct_types += ' ' + argfull + semi
async_db400_args += ' myptr->' + argname + comma
async_copyin_args += ' myptr->' + argname + ' = ' + argname + ';' + '\n'
pase_cli_dump_h_proto += 'void dump_' + call_name + '(SQLRETURN sqlrc, ' + normal_call_args + ' );' + '\n'
pase_cli_dump_c_main += 'void dump_' + call_name + '(SQLRETURN sqlrc, ' + normal_call_args + ' ) {' + '\n'
pase_cli_dump_c_main += ' if (dev_go(sqlrc,"' + call_name.lower() + '")) {' + '\n'
pase_cli_dump_c_main += ' char mykey[256];' + '\n'
pase_cli_dump_c_main += ' printf_key(mykey,"' + call_name + '");' + '\n'
pase_cli_dump_c_main += ' printf_clear();' + '\n'
pase_cli_dump_c_main += ' printf_sqlrc_head_foot((char *)&mykey, sqlrc, 1);' + '\n'
pase_cli_dump_c_main += ' printf_stack(mykey);' + '\n'
pase_cli_dump_c_main += ' printf_sqlrc_status((char *)&mykey, sqlrc);' + '\n'
args = dump_args.split()
sigs = dump_sigs.split()
dump_handle = ''
dump_type = ''
i = 0
for arg in args:
sig = sigs[i]
pase_cli_dump_c_main += ' printf_format("%s.parm %s %s 0x%p (%d)\\n",mykey,"' + sig + '","' + arg + '",' + arg + ',' + arg + ');' + '\n'
if '*' in sig or 'SQLPOINTER' in sig:
pase_cli_dump_c_main += ' printf_hexdump(mykey,' + arg + ',80);' + '\n'
elif 'SQLHDBC' in sig:
dump_handle = arg
dump_type = 'SQL_HANDLE_DBC'
elif 'SQLHSTMT' in sig:
dump_handle = arg
dump_type = 'SQL_HANDLE_STMT'
elif 'SQLHDESC' in sig:
dump_handle = arg
dump_type = 'SQL_HANDLE_DESC'
i += 1
pase_cli_dump_c_main += ' printf_sqlrc_head_foot((char *)&mykey, sqlrc, 0);' + '\n'
pase_cli_dump_c_main += ' dev_dump();' + '\n'
pase_cli_dump_c_main += ' if (sqlrc < SQL_SUCCESS) {' + '\n'
if 'SQL' in dump_type:
pase_cli_dump_c_main += ' printf_sql_diag(' + dump_type + ',' + dump_handle + ');' + '\n'
pase_cli_dump_c_main += ' printf_force_SIGQUIT((char *)&mykey);' + '\n'
pase_cli_dump_c_main += ' }' + '\n'
pase_cli_dump_c_main += ' }' + '\n'
pase_cli_dump_c_main += '}' + '\n'
if c400:
pase_cli_any_h_proto += ' * ' + call_retv + ' ' + call_name + '(' + normal_call_args + ' );' + '\n'
if c400_CCSID:
pase_cli_custom_h_proto += call_retv + ' ' + 'custom_' + call_name + '(' + normal_call_args + ' );' + '\n'
else:
pase_cli_lib_db400_h_proto += call_retv + ' libdb400_' + call_name + '(' + normal_call_args + ' );' + '\n'
pase_cli_lib_db400_c_main += call_retv + ' libdb400_' + call_name + '(' + normal_call_args + ' ) {' + '\n'
pase_cli_lib_db400_c_main += ' SQLRETURN sqlrc = SQL_SUCCESS;' + '\n'
if 'W' in call_name:
pase_cli_lib_db400_c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
pase_cli_lib_db400_c_main += ' return sqlrc;' + '\n'
pase_cli_lib_db400_c_main += '}' + '\n'
elif 'SQLColAttributes' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_col_attributes(call_name, normal_db400_args)
elif 'SQLColumnPrivileges' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_column_privileges(call_name, normal_db400_args)
elif 'SQLColumns' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_columns(call_name, normal_db400_args)
elif 'SQLConnect' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_connect(call_name, normal_db400_args)
elif 'SQLDataSources' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_data_sources(call_name, normal_db400_args)
elif 'SQLDescribeCol' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_describe_col(call_name, normal_db400_args)
elif 'SQLDriverConnect' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_driver_connect(call_name, normal_db400_args)
elif 'SQLError' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_error(call_name, normal_db400_args)
elif 'SQLExecDirect' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_exec_direct(call_name, normal_db400_args)
elif 'SQLForeignKeys' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_foreign_keys(call_name, normal_db400_args)
elif 'SQLGetConnectAttr' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_get_connect_attr(call_name, normal_db400_args)
elif 'SQLGetConnectOption' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_get_connect_option(call_name, normal_db400_args)
elif 'SQLGetCursorName' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_get_cursor_name(call_name, normal_db400_args)
elif 'SQLGetDescField' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_get_desc_field(call_name, normal_db400_args)
elif 'SQLGetDescRec' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_get_desc_rec(call_name, normal_db400_args)
elif 'SQLGetDiagField' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_get_diag_field(call_name, normal_db400_args)
elif 'SQLGetDiagRec' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_get_diag_rec(call_name, normal_db400_args)
elif 'SQLGetEnvAttr' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_get_env_attr(call_name, normal_db400_args)
elif 'SQLGetInfo' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_get_info(call_name, normal_db400_args)
elif 'SQLGetPosition' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_get_position(call_name, normal_db400_args)
elif 'SQLNativeSql' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_native_sql(call_name, normal_db400_args)
elif 'SQLParamData' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_param_data(call_name, normal_db400_args)
elif 'SQLPrepare' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_prepare(call_name, normal_db400_args)
elif 'SQLPrimaryKeys' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_primary_keys(call_name, normal_db400_args)
elif 'SQLProcedureColumns' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_procedure_columns(call_name, normal_db400_args)
elif 'SQLProcedures' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_procedures(call_name, normal_db400_args)
elif 'SQLSetConnectAttr' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_set_connect_attr(call_name, normal_db400_args)
elif 'SQLSetConnectOption' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_set_connect_option(call_name, normal_db400_args)
elif 'SQLSetCursorName' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_set_cursor_name(call_name, normal_db400_args)
elif 'SQLSetEnvAttr' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_set_env_attr(call_name, normal_db400_args)
elif 'SQLSpecialColumns' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_special_columns(call_name, normal_db400_args)
elif 'SQLStatistics' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_statistics(call_name, normal_db400_args)
elif 'SQLTablePrivileges' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_table_privileges(call_name, normal_db400_args)
elif 'SQLTables' in call_name:
pase_cli_lib_db400_c_main += non_utf_sql_tables(call_name, normal_db400_args)
else:
pase_cli_lib_db400_c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n'
pase_cli_lib_db400_c_main += ' return sqlrc;' + '\n'
pase_cli_lib_db400_c_main += '}' + '\n'
libdb400_exp += 'libdb400_' + call_name + '\n'
else:
pase_cli_only400_h_proto += call_retv + ' ' + call_name + '(' + normal_call_args + ' );' + '\n'
pase_cli_custom_h_proto += call_retv + ' ' + 'custom_' + call_name + '(' + normal_call_args + ' );' + '\n'
libdb400_exp += call_name + '\n'
if c400_CCSID:
pase_cli_async_c_main += 'int SQLOverrideCCSID400(int newCCSID)' + '\n'
else:
pase_cli_async_c_main += call_retv + ' ' + call_name + '(' + normal_call_args + ' )' + '\n'
pase_cli_async_c_main += '{' + '\n'
pase_cli_async_c_main += ' SQLRETURN sqlrc = SQL_SUCCESS;' + '\n'
if call_name == 'SQLAllocEnv':
pase_cli_async_c_main += pase_cli_async_c_main_sql_alloc_env(ile_or_custom_call, call_name, normal_db400_args)
elif call_name == 'SQLAllocConnect':
pase_cli_async_c_main += pase_cli_async_c_main_sql_alloc_connect(ile_or_custom_call, call_name, normal_db400_args)
elif call_name == 'SQLAllocStmt':
pase_cli_async_c_main += pase_cli_async_c_main_sql_alloc_stmt(ile_or_custom_call, call_name, normal_db400_args)
elif call_name == 'SQLAllocHandle':
pase_cli_async_c_main += pase_cli_async_c_main_sql_alloc_handle(ile_or_custom_call, call_name, normal_db400_args)
elif call_name == 'SQLFreeEnv':
pase_cli_async_c_main += pase_cli_async_c_main_sql_free_env(ile_or_custom_call, call_name, normal_db400_args)
elif call_name == 'SQLFreeConnect':
pase_cli_async_c_main += pase_cli_async_c_main_sql_free_connect(ile_or_custom_call, call_name, normal_db400_args)
elif call_name == 'SQLFreeStmt':
pase_cli_async_c_main += pase_cli_async_c_main_sql_free_stmt(ile_or_custom_call, call_name, normal_db400_args)
elif call_name == 'SQLFreeHandle':
pase_cli_async_c_main += pase_cli_async_c_main_sql_free_handle(ile_or_custom_call, call_name, normal_db400_args)
elif c400_CCSID:
pase_cli_async_c_main += ' sqlrc = custom_' + call_name + '(' + normal_db400_args + ' );' + '\n'
else:
pase_cli_async_c_main += ' int myccsid = init_CCSID400(0);' + '\n'
if call_name == 'SQLDisconnect':
pase_cli_async_c_main += sql_disconnect_check_persistent('hdbc', 'return SQL_ERROR;', '/* return now */')
if argtype1st == 'SQLHENV':
if ile_or_custom_call == 'custom_':
pase_cli_async_c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
else:
pase_cli_async_c_main += ' switch(myccsid) {' + '\n'
pase_cli_async_c_main += ' case 1208: /* UTF-8 */' + '\n'
pase_cli_async_c_main += ' case 1200: /* UTF-16 */' + '\n'
pase_cli_async_c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
pase_cli_async_c_main += ' break;' + '\n'
pase_cli_async_c_main += ' default:' + '\n'
pase_cli_async_c_main += ' sqlrc = libdb400_' + call_name + '(' + normal_db400_args + ' );' + '\n'
pase_cli_async_c_main += ' break;' + '\n'
pase_cli_async_c_main += ' }' + '\n'
pase_cli_async_c_main += ' if (init_cli_trace()) {' + '\n'
pase_cli_async_c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n'
pase_cli_async_c_main += ' }' + '\n'
elif argtype1st == 'SQLHDBC':
pase_cli_async_c_main += ' init_table_lock(' + argname1st + ', 0);' + '\n'
if ile_or_custom_call == 'custom_':
pase_cli_async_c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
else:
pase_cli_async_c_main += ' switch(myccsid) {' + '\n'
pase_cli_async_c_main += ' case 1208: /* UTF-8 */' + '\n'
pase_cli_async_c_main += ' case 1200: /* UTF-16 */' + '\n'
pase_cli_async_c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
pase_cli_async_c_main += ' break;' + '\n'
pase_cli_async_c_main += ' default:' + '\n'
pase_cli_async_c_main += ' sqlrc = libdb400_' + call_name + '(' + normal_db400_args + ' );' + '\n'
pase_cli_async_c_main += ' break;' + '\n'
pase_cli_async_c_main += ' }' + '\n'
pase_cli_async_c_main += ' if (init_cli_trace()) {' + '\n'
pase_cli_async_c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n'
pase_cli_async_c_main += ' }' + '\n'
pase_cli_async_c_main += ' init_table_unlock(' + argname1st + ', 0);' + '\n'
elif argtype1st == 'SQLHSTMT':
pase_cli_async_c_main += ' init_table_lock(' + argname1st + ', 1);' + '\n'
if ile_or_custom_call == 'custom_':
pase_cli_async_c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
else:
pase_cli_async_c_main += ' switch(myccsid) {' + '\n'
pase_cli_async_c_main += ' case 1208: /* UTF-8 */' + '\n'
pase_cli_async_c_main += ' case 1200: /* UTF-16 */' + '\n'
pase_cli_async_c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
pase_cli_async_c_main += ' break;' + '\n'
pase_cli_async_c_main += ' default:' + '\n'
pase_cli_async_c_main += ' sqlrc = libdb400_' + call_name + '(' + normal_db400_args + ' );' + '\n'
pase_cli_async_c_main += ' break;' + '\n'
pase_cli_async_c_main += ' }' + '\n'
pase_cli_async_c_main += ' if (init_cli_trace()) {' + '\n'
pase_cli_async_c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n'
pase_cli_async_c_main += ' }' + '\n'
pase_cli_async_c_main += ' init_table_unlock(' + argname1st + ', 1);' + '\n'
elif argtype1st == 'SQLHDESC':
pase_cli_async_c_main += ' init_table_lock(' + argname1st + ', 1);' + '\n'
if ile_or_custom_call == 'custom_':
pase_cli_async_c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
else:
pase_cli_async_c_main += ' switch(myccsid) {' + '\n'
pase_cli_async_c_main += ' case 1208: /* UTF-8 */' + '\n'
pase_cli_async_c_main += ' case 1200: /* UTF-16 */' + '\n'
pase_cli_async_c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
pase_cli_async_c_main += ' break;' + '\n'
pase_cli_async_c_main += ' default:' + '\n'
pase_cli_async_c_main += ' sqlrc = libdb400_' + call_name + '(' + normal_db400_args + ' );' + '\n'
pase_cli_async_c_main += ' break;' + '\n'
pase_cli_async_c_main += ' }' + '\n'
pase_cli_async_c_main += ' if (init_cli_trace()) {' + '\n'
pase_cli_async_c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n'
pase_cli_async_c_main += ' }' + '\n'
pase_cli_async_c_main += ' init_table_unlock(' + argname1st + ', 1);' + '\n'
else:
if ile_or_custom_call == 'custom_':
pase_cli_async_c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
else:
pase_cli_async_c_main += ' switch(myccsid) {' + '\n'
pase_cli_async_c_main += ' case 1208: /* UTF-8 */' + '\n'
pase_cli_async_c_main += ' case 1200: /* UTF-16 */' + '\n'
pase_cli_async_c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n'
pase_cli_async_c_main += ' break;' + '\n'
pase_cli_async_c_main += ' default:' + '\n'
pase_cli_async_c_main += ' sqlrc = libdb400_' + call_name + '(' + normal_db400_args + ' );' + '\n'
pase_cli_async_c_main += ' break;' + '\n'
pase_cli_async_c_main += ' }' + '\n'
pase_cli_async_c_main += ' if (init_cli_trace()) {' + '\n'
pase_cli_async_c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n'
pase_cli_async_c_main += ' }' + '\n'
pase_cli_async_c_main += ' return sqlrc;' + '\n'
pase_cli_async_c_main += '}' + '\n'
if c400 and c400_CCSID == False:
pase_cli_ile_h_proto += call_retv + ' ILE_' + call_name + '(' + normal_call_args + ' );' + '\n'
pase_cli_ile_h_struct += 'typedef struct ' + struct_ile_name + ' {' + ILE_struct_types + ' } ' + struct_ile_name + ';' + '\n'
pase_cli_ile_c_symbol += 'SQLINTEGER ' + struct_ile_flag + ';' + '\n'
pase_cli_ile_c_symbol += 'SQLCHAR ' + struct_ile_buf + '[132];' + '\n'
pase_cli_ile_c_main += call_retv + ' ILE_' + call_name + '(' + normal_call_args + ' )' + '\n'
pase_cli_ile_c_main += '{' + '\n'
pase_cli_ile_c_main += ' int rc = 0;' + '\n'
pase_cli_ile_c_main += ' SQLRETURN sqlrc = SQL_SUCCESS;' + '\n'
if 'SQLParamData' in call_name:
pase_cli_ile_c_main += ile_sql_param_data_copy_var()
if 'SQLGetDescField' in call_name:
pase_cli_ile_c_main += ile_sql_get_desc_field_copy_var()
pase_cli_ile_c_main += ' int actMark = 0;' + '\n'
pase_cli_ile_c_main += ' char * ileSymPtr = (char *) NULL;' + '\n'
pase_cli_ile_c_main += ' ' + struct_ile_name + ' * arglist = (' + struct_ile_name + ' *) NULL;' + '\n'
pase_cli_ile_c_main += ' char buffer[ sizeof(' + struct_ile_name + ') + 16 ];' + '\n'
pase_cli_ile_c_main += ' static arg_type_t ' + struct_ile_sig + '[] = {' + ILE_struct_sigs + ', ARG_END };' + '\n'
pase_cli_ile_c_main += ' arglist = (' + struct_ile_name + ' *)ROUND_QUAD(buffer);' + '\n'
pase_cli_ile_c_main += ' ileSymPtr = (char *)ROUND_QUAD(&' + struct_ile_buf + ');' + '\n'
pase_cli_ile_c_main += ' memset(buffer,0,sizeof(buffer));' + '\n'
pase_cli_ile_c_main += ' actMark = init_cli_srvpgm();' + '\n'
pase_cli_ile_c_main += ' if (!' + struct_ile_flag + ') {' + '\n'
pase_cli_ile_c_main += ' rc = _ILESYM((ILEpointer *)ileSymPtr, actMark, "' + call_name + '");' + '\n'
pase_cli_ile_c_main += ' if (rc < 0) {' + '\n'
pase_cli_ile_c_main += ' return SQL_ERROR;' + '\n'
pase_cli_ile_c_main += ' }' + '\n'
pase_cli_ile_c_main += ' ' + struct_ile_flag + ' = 1;' + '\n'
pase_cli_ile_c_main += ' }' + '\n'
pase_cli_ile_c_main += ILE_copyin_args
if 'SQLParamData' in call_name:
pase_cli_ile_c_main += ile_sql_param_data_copy_in()
if 'SQLGetDescField' in call_name:
pase_cli_ile_c_main += ile_sql_get_desc_field_copy_in()
pase_cli_ile_c_main += ' rc = _ILECALL((ILEpointer *)ileSymPtr, &arglist->base, ' + struct_ile_sig + ', RESULT_INT32);' + '\n'
pase_cli_ile_c_main += ' if (rc != ILECALL_NOERROR) {' + '\n'
pase_cli_ile_c_main += ' return SQL_ERROR;' + '\n'
pase_cli_ile_c_main += ' }' + '\n'
if 'SQLParamData' in call_name:
pase_cli_ile_c_main += ile_sql_param_data_copy_out()
if 'SQLGetDescField' in call_name:
pase_cli_ile_c_main += ile_sql_get_desc_field_copy_out()
pase_cli_ile_c_main += ' return arglist->base.result.s_int32.r_int32;' + '\n'
pase_cli_ile_c_main += '}' + '\n'
if call_name == 'SQLAllocEnv':
continue
elif call_name == 'SQLAllocConnect':
continue
elif call_name == 'SQLAllocStmt':
continue
elif call_name == 'SQLAllocHandle':
continue
elif call_name == 'SQLFreeEnv':
continue
elif call_name == 'SQLFreeConnect':
continue
elif call_name == 'SQLFreeStmt':
continue
elif call_name == 'SQLFreeHandle':
continue
elif c400_CCSID:
continue
async_call_args = normal_call_args + ', void * callback'
async_struct_types += ' void * callback;'
async_copyin_args += ' myptr->callback = callback;' + '\n'
tmp__pase_cli_async_comment = '/* void ' + call_name + 'Callback(' + struct_name + '* ); */'
pase_cli_async_h_proto_async += 'pthread_t ' + call_name + 'Async (' + async_call_args + ' );' + '\n'
pase_cli_async_h_proto_join += tmp_PaseCliAsync_comment + '\n'
pase_cli_async_h_proto_join += struct_name + ' * ' + call_name + 'Join (pthread_t tid, SQLINTEGER flag);' + '\n'
libdb400_exp += call_name + 'Async' + '\n'
libdb400_exp += call_name + 'Join' + '\n'
if c400:
libdb400_exp += 'ILE_' + call_name + '\n'
pase_cli_async_h_struct += 'typedef struct ' + struct_name + ' {' + async_struct_types + ' } ' + struct_name + ';' + '\n'
pase_cli_async_c_main += 'void * ' + call_name + 'Thread (void *ptr)' + '\n'
pase_cli_async_c_main += '{' + '\n'
pase_cli_async_c_main += ' SQLRETURN sqlrc = SQL_SUCCESS;' + '\n'
pase_cli_async_c_main += ' int myccsid = init_CCSID400(0);' + '\n'
pase_cli_async_c_main += ' ' + struct_name + ' * myptr = (' + struct_name + ' *) ptr;' + '\n'
if call_name == 'SQLDisconnect':
pase_cli_async_c_main += sql_disconnect_check_persistent('myptr->hdbc', 'pthread_exit((void *)myptr);', 'myptr->sqlrc = SQL_ERROR;')
if argtype1st == 'SQLHENV':
pase_cli_async_c_main += ' /* not lock */' + '\n'
elif argtype1st == 'SQLHDBC':
pase_cli_async_c_main += ' init_table_lock(myptr->' + argname1st + ', 0);' + '\n'
elif argtype1st == 'SQLHSTMT':
pase_cli_async_c_main += ' init_table_lock(myptr->' + argname1st + ', 1);' + '\n'
elif argtype1st == 'SQLHDESC':
pase_cli_async_c_main += ' init_table_lock(myptr->' + argname1st + ', 1);' + '\n'
if ile_or_custom_call == 'custom_':
pase_cli_async_c_main += ' myptr->sqlrc = ' + ile_or_custom_call + call_name + '(' + async_db400_args + ' );' + '\n'
else:
pase_cli_async_c_main += ' switch(myccsid) {' + '\n'
pase_cli_async_c_main += ' case 1208: /* UTF-8 */' + '\n'
pase_cli_async_c_main += ' case 1200: /* UTF-16 */' + '\n'
pase_cli_async_c_main += ' myptr->sqlrc = ' + ile_or_custom_call + call_name + '(' + async_db400_args + ' );' + '\n'
pase_cli_async_c_main += ' break;' + '\n'
pase_cli_async_c_main += ' default:' + '\n'
pase_cli_async_c_main += ' myptr->sqlrc = libdb400_' + call_name + '(' + async_db400_args + ' );' + '\n'
pase_cli_async_c_main += ' break;' + '\n'
pase_cli_async_c_main += ' }' + '\n'
pase_cli_async_c_main += ' if (init_cli_trace()) {' + '\n'
pase_cli_async_c_main += ' dump_' + call_name + '(myptr->sqlrc, ' + async_db400_args + ' );' + '\n'
pase_cli_async_c_main += ' }' + '\n'
if argtype1st == 'SQLHENV':
pase_cli_async_c_main += ' /* not lock */' + '\n'
elif argtype1st == 'SQLHDBC':
pase_cli_async_c_main += ' init_table_unlock(myptr->' + argname1st + ', 0);' + '\n'
elif argtype1st == 'SQLHSTMT':
pase_cli_async_c_main += ' init_table_unlock(myptr->' + argname1st + ', 1);' + '\n'
elif argtype1st == 'SQLHDESC':
pase_cli_async_c_main += ' init_table_unlock(myptr->' + argname1st + ', 1);' + '\n'
pase_cli_async_c_main += ' ' + tmp_PaseCliAsync_comment + '\n'
pase_cli_async_c_main += ' if (myptr->callback) {' + '\n'
pase_cli_async_c_main += ' void (*ptrFunc)(' + struct_name + '* ) = myptr->callback;' + '\n'
pase_cli_async_c_main += ' ptrFunc( myptr );' + '\n'
pase_cli_async_c_main += ' }' + '\n'
pase_cli_async_c_main += ' pthread_exit((void *)myptr);' + '\n'
pase_cli_async_c_main += '}' + '\n'
pase_cli_async_c_main += 'pthread_t ' + call_name + 'Async (' + async_call_args + ' )' + '\n'
pase_cli_async_c_main += '{' + '\n'
pase_cli_async_c_main += ' int rc = 0;' + '\n'
pase_cli_async_c_main += ' pthread_t tid = 0;' + '\n'
pase_cli_async_c_main += ' ' + struct_name + ' * myptr = (' + struct_name + ' *) malloc(sizeof(' + struct_name + '));' + '\n'
pase_cli_async_c_main += ' myptr->sqlrc = SQL_SUCCESS;' + '\n'
pase_cli_async_c_main += async_copyin_args
pase_cli_async_c_main += ' rc = pthread_create(&tid, NULL, ' + call_name + 'Thread, (void *)myptr);' + '\n'
pase_cli_async_c_main += ' return tid;' + '\n'
pase_cli_async_c_main += '}' + '\n'
pase_cli_async_c_main += struct_name + ' * ' + call_name + 'Join (pthread_t tid, SQLINTEGER flag)' + '\n'
pase_cli_async_c_main += '{' + '\n'
pase_cli_async_c_main += ' ' + struct_name + ' * myptr = (' + struct_name + ' *) NULL;' + '\n'
pase_cli_async_c_main += ' int active = 0;' + '\n'
if argtype1st == 'SQLHENV':
pase_cli_async_c_main += ' /* not lock */' + '\n'
elif argtype1st == 'SQLHDBC':
pase_cli_async_c_main += ' active = init_table_in_progress(tid, 0);' + '\n'
elif argtype1st == 'SQLHSTMT':
pase_cli_async_c_main += ' active = init_table_in_progress(tid, 1);' + '\n'
elif argtype1st == 'SQLHDESC':
pase_cli_async_c_main += ' active = init_table_in_progress(tid, 1);' + '\n'
pase_cli_async_c_main += ' if (flag == SQL400_FLAG_JOIN_WAIT || !active) {' + '\n'
pase_cli_async_c_main += ' pthread_join(tid,(void**)&myptr);' + '\n'
pase_cli_async_c_main += ' } else {' + '\n'
pase_cli_async_c_main += ' return (' + struct_name + ' *) NULL;' + '\n'
pase_cli_async_c_main += ' }' + '\n'
pase_cli_async_c_main += ' return myptr;' + '\n'
pase_cli_async_c_main += '}' + '\n'
file_pase_incl = ''
file_pase_incl += '#include <stdio.h>' + '\n'
file_pase_incl += '#include <stdlib.h>' + '\n'
file_pase_incl += '#include <unistd.h>' + '\n'
file_pase_incl += '#include <dlfcn.h>' + '\n'
file_pase_incl += '#include <sqlcli1.h>' + '\n'
file_pase_incl += '#include <as400_types.h>' + '\n'
file_pase_incl += '#include <as400_protos.h>' + '\n'
file_local_incl = ''
file_local_incl += '#include "PaseCliInit.h"' + '\n'
file_local_incl += '#include "PaseCliAsync.h"' + '\n'
file__pase_cli_ile_c = ''
file__pase_cli_ile_c += file_pase_incl
file__pase_cli_ile_c += file_local_incl
file__pase_cli_ile_c += '' + '\n'
file__pase_cli_ile_c += ' /* gcc compiler' + '\n'
file__pase_cli_ile_c += ' * as400_types.h (edit change required)' + '\n'
file__pase_cli_ile_c += ' * #if defined( __GNUC__ )' + '\n'
file__pase_cli_ile_c += ' * long double align __attribute__((aligned(16)));' + '\n'
file__pase_cli_ile_c += ' * #else ' + '\n'
file__pase_cli_ile_c += ' * long double;' + '\n'
file__pase_cli_ile_c += ' * #endif ' + '\n'
file__pase_cli_ile_c += ' * ' + '\n'
file__pase_cli_ile_c += ' * Use we also need cast ulong to match size of pointer 32/64 ' + '\n'
file__pase_cli_ile_c += ' * arglist->ohnd.s.addr = (ulong) ohnd;' + '\n'
file__pase_cli_ile_c += ' */' + '\n'
file__pase_cli_ile_c += '' + '\n'
file__pase_cli_ile_c += '#define ROUND_QUAD(x) (((size_t)(x) + 0xf) & ~0xf)' + '\n'
file__pase_cli_ile_c += '' + '\n'
file__pase_cli_ile_c += PaseCliILE_c_symbol
file__pase_cli_ile_c += '' + '\n'
file__pase_cli_ile_c += '/* ILE call structures */' + '\n'
file__pase_cli_ile_c += '' + '\n'
file__pase_cli_ile_c += PaseCliILE_h_struct + '\n'
file__pase_cli_ile_c += '' + '\n'
file__pase_cli_ile_c += PaseCliILE_c_main
file__pase_cli_ile_c += '' + '\n'
with open('PaseCliILE_gen.c', 'w') as text_file:
text_file.write(file_PaseCliILE_c)
file__pase_cli_lib_db400_c = ''
file__pase_cli_lib_db400_c += file_pase_incl
file__pase_cli_lib_db400_c += file_local_incl
file__pase_cli_lib_db400_c += '' + '\n'
file__pase_cli_lib_db400_c += '#define DFTCOLSIZE 18' + '\n'
file__pase_cli_lib_db400_c += '#define SQL_MAXINTVAL_REASONABLE 131072' + '\n'
file__pase_cli_lib_db400_c += '' + '\n'
file__pase_cli_lib_db400_c += PaseCliLibDB400_c_symbol
file__pase_cli_lib_db400_c += '' + '\n'
file__pase_cli_lib_db400_c += non_utf_copy_in()
file__pase_cli_lib_db400_c += non_utf_copy_in_free()
file__pase_cli_lib_db400_c += non_utf_copy_out()
file__pase_cli_lib_db400_c += non_utf_isconvert_ordinal()
file__pase_cli_lib_db400_c += '' + '\n'
file__pase_cli_lib_db400_c += PaseCliLibDB400_c_main
file__pase_cli_lib_db400_c += '' + '\n'
with open('PaseCliLibDB400_gen.c', 'w') as text_file:
text_file.write(file_PaseCliLibDB400_c)
file__pase_cli_async_c = ''
file__pase_cli_async_c += file_pase_incl
file__pase_cli_async_c += file_local_incl
file__pase_cli_async_c += '' + '\n'
file__pase_cli_async_c += '' + '\n'
file__pase_cli_async_c += PaseCliAsync_c_main
with open('PaseCliAsync_gen.c', 'w') as text_file:
text_file.write(file_PaseCliAsync_c)
file__pase_cli_dump_c = ''
file__pase_cli_dump_c += file_pase_incl
file__pase_cli_dump_c += file_local_incl
file__pase_cli_dump_c += '#include "PaseCliDev.h"' + '\n'
file__pase_cli_dump_c += '#include "PaseCliPrintf.h"' + '\n'
file__pase_cli_dump_c += '' + '\n'
file__pase_cli_dump_c += '' + '\n'
file__pase_cli_dump_c += PaseCliDump_c_main
with open('PaseCliDump_gen.c', 'w') as text_file:
text_file.write(file_PaseCliDump_c)
file__pase_cli_async_h = ''
file__pase_cli_async_h += '#ifndef _PASECLIASYNC_H' + '\n'
file__pase_cli_async_h += '#define _PASECLIASYNC_H' + '\n'
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += file_pase_incl
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += '#ifdef __cplusplus' + '\n'
file__pase_cli_async_h += 'extern "C" {' + '\n'
file__pase_cli_async_h += '#endif' + '\n'
file__pase_cli_async_h += '/* ===================================================' + '\n'
file__pase_cli_async_h += ' * Using the driver' + '\n'
file__pase_cli_async_h += ' * ===================================================' + '\n'
file__pase_cli_async_h += ' */' + '\n'
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += '/* ' + '\n'
file__pase_cli_async_h += ' * SQL400Environment -- set the mode of driver' + '\n'
file__pase_cli_async_h += ' * ' + '\n'
file__pase_cli_async_h += ' * === UTF-8 mode, most popular AIX/PASE/Linux ===' + '\n'
file__pase_cli_async_h += ' * SQLOverrideCCSID400(1208) -- UTF-8 mode, CLI normal/async direct ILE call' + '\n'
file__pase_cli_async_h += ' * -->SQLExecDirect(Async)-->ILE_SQLExecDirect-->DB2' + '\n'
file__pase_cli_async_h += ' * -->SQLExecDirectW(Async)-->ILE_SQLExecDirectW-->DB2' + '\n'
file__pase_cli_async_h += ' * ' + '\n'
file__pase_cli_async_h += ' * === UTF-8 mode, most popular Windows/Java ===' + '\n'
file__pase_cli_async_h += ' * SQLOverrideCCSID400(1200) -- UTF-16 mode, CLI normal/async direct ILE call' + '\n'
file__pase_cli_async_h += ' * -->SQLExecDirect(Async)-->ILE_SQLExecDirectW-->DB2' + '\n'
file__pase_cli_async_h += ' * -->SQLExecDirectW(Async)-->ILE_SQLExecDirectW-->DB2' + '\n'
file__pase_cli_async_h += ' * ' + '\n'
file__pase_cli_async_h += ' * === PASE default (original libdb400.a) ===' + '\n'
file__pase_cli_async_h += ' * SQLOverrideCCSID400(other) -- PASE ccsid, CLI API calls PASE libdb400.a' + '\n'
file__pase_cli_async_h += ' * -->SQLExecDirect(Async)-->PASE libdb400.a(SQLExecDirect)-->DB2' + '\n'
file__pase_cli_async_h += ' * -->SQLExecDirectW(Async)-->ILE_SQLExecDirectW-->DB2 (*)' + '\n'
file__pase_cli_async_h += ' * ' + '\n'
file__pase_cli_async_h += ' * PASE ccsid setting occurs before any other CLI operations' + '\n'
file__pase_cli_async_h += ' * at the environment level. Therefore the driver mode is' + '\n'
file__pase_cli_async_h += ' * established (restricted, if you choose). ' + '\n'
file__pase_cli_async_h += ' * ' + '\n'
file__pase_cli_async_h += ' * 1) non-Unicode interfaces (call old libdb400.a, messy stuff):' + '\n'
file__pase_cli_async_h += ' * int ccsid = 819;' + '\n'
file__pase_cli_async_h += ' * env attr SQL400_ATTR_PASE_CCSID &ccsid -- set pase ccsid' + '\n'
file__pase_cli_async_h += ' * ' + '\n'
file__pase_cli_async_h += ' * 2) UTF8 interfaces (call direct to ILE DB2):' + '\n'
file__pase_cli_async_h += ' * int ccsid = 1208;' + '\n'
file__pase_cli_async_h += ' * env attr SQL400_ATTR_PASE_CCSID &ccsid -- set pase ccsid' + '\n'
file__pase_cli_async_h += ' * if ccsid == 1208:' + '\n'
file__pase_cli_async_h += ' * env attr SQL_ATTR_UTF8 &true -- no conversion required by PASE' + '\n'
file__pase_cli_async_h += ' * ' + '\n'
file__pase_cli_async_h += ' * 3) UTF16 wide interfaces (call direct to ILE DB2):' + '\n'
file__pase_cli_async_h += ' * **** NEVER set PASE_CCSID or ATTR_UTF8 in UTF-16 mode. ****' + '\n'
file__pase_cli_async_h += ' * So, database exotic ebcdic column and PASE binds c type as WVARCHAR/WCHAR output is UTF16?' + '\n'
file__pase_cli_async_h += ' * Yes, the database will do the conversion from EBCDIC to UTF16 for data bound as WVARCHAR/WCHAR.' + '\n'
file__pase_cli_async_h += ' * not sure about DBCLOB -- I want to guess that is bound as UTF-16, not 100% sure.' + '\n'
file__pase_cli_async_h += ' * ' + '\n'
file__pase_cli_async_h += ' * IF your data not UTF-8 or UTF-16, interfaces to convert (experimental).' + '\n'
file__pase_cli_async_h += ' * SQL400ToUtf8 -- use before passing to CLI normal interfaces' + '\n'
file__pase_cli_async_h += ' * SQL400FromUtf8 -- use return output normal CLI (if needed)' + '\n'
file__pase_cli_async_h += ' * SQL400ToUtf16 -- use before passing to CLI wide interfaces' + '\n'
file__pase_cli_async_h += ' * SQL400FromUtf16 -- use return output wide CLI (if needed)' + '\n'
file__pase_cli_async_h += ' * ' + '\n'
file__pase_cli_async_h += ' * A choice of exported APIs (SQLExecDirect one of many):' + '\n'
file__pase_cli_async_h += ' * ' + '\n'
file__pase_cli_async_h += ' * === CLI APIs UTF-8 or APIWs UTF-16 ===' + '\n'
file__pase_cli_async_h += ' * === choose async and/or normal wait ===' + '\n'
file__pase_cli_async_h += ' * SQLRETURN SQLExecDirect(..);' + '\n'
file__pase_cli_async_h += ' * SQLRETURN SQLExecDirectW(..);' + '\n'
file__pase_cli_async_h += ' * ' + '\n'
file__pase_cli_async_h += ' * == callback or reap/join with async ===' + '\n'
file__pase_cli_async_h += ' * pthread_t SQLExecDirectAsync(..);' + '\n'
file__pase_cli_async_h += ' * pthread_t SQLExecDirectWAsync(..);' + '\n'
file__pase_cli_async_h += ' * void SQLExecDirectCallback(SQLExecDirectStruct* );' + '\n'
file__pase_cli_async_h += ' * SQLExecDirectStruct * SQLExecDirectJoin (pthread_t tid, SQLINTEGER flag);' + '\n'
file__pase_cli_async_h += ' * void SQLExecDirectWCallback(SQLExecDirectWStruct* );' + '\n'
file__pase_cli_async_h += ' * SQLExecDirectWStruct * SQLExecDirectWJoin (pthread_t tid, SQLINTEGER flag);' + '\n'
file__pase_cli_async_h += ' * ' + '\n'
file__pase_cli_async_h += ' * === bypass all, call PASE libdb400.a directly (not recommended) ===' + '\n'
file__pase_cli_async_h += ' * SQLRETURN libdb400_SQLExecDirect(..);' + '\n'
file__pase_cli_async_h += ' * SQLRETURN libdb400_SQLExecDirectW(..); (*)' + '\n'
file__pase_cli_async_h += ' * ' + '\n'
file__pase_cli_async_h += ' * === bypass all, call ILE directly (not recommended) ===' + '\n'
file__pase_cli_async_h += ' * SQLRETURN ILE_SQLExecDirect(..);' + '\n'
file__pase_cli_async_h += ' * SQLRETURN ILE_SQLExecDirectW(..);' + '\n'
file__pase_cli_async_h += ' * ' + '\n'
file__pase_cli_async_h += ' */' + '\n'
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += '/* ===================================================' + '\n'
file__pase_cli_async_h += ' * CUSTOM interfaces' + '\n'
file__pase_cli_async_h += ' * ===================================================' + '\n'
file__pase_cli_async_h += ' */' + '\n'
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += '/* Use:' + '\n'
file__pase_cli_async_h += ' * SQL400Environment ( ..., SQLPOINTER options )' + '\n'
file__pase_cli_async_h += ' * SQL400Connect ( ..., SQLPOINTER options )' + '\n'
file__pase_cli_async_h += ' * SQL400SetAttr ( ..., SQLPOINTER options )' + '\n'
file__pase_cli_async_h += ' * CTOR:' + '\n'
file__pase_cli_async_h += ' * SQL400AddAttr' + '\n'
file__pase_cli_async_h += ' * Struct:' + '\n'
file__pase_cli_async_h += ' * SQL400AttrStruct' + '\n'
file__pase_cli_async_h += ' * e - EnvAttr' + '\n'
file__pase_cli_async_h += ' * c - ConnectAttr' + '\n'
file__pase_cli_async_h += ' * s - StmtAttr' + '\n'
file__pase_cli_async_h += ' * o - StmtOption' + '\n'
file__pase_cli_async_h += ' */' + '\n'
file__pase_cli_async_h += '/* CLI hidden attributes */' + '\n'
file__pase_cli_async_h += '#define SQL400_ATTR_PASE_CCSID 10011' + '\n'
file__pase_cli_async_h += '#define SQL400_ATTR_CONN_JDBC 10201' + '\n'
file__pase_cli_async_h += '/* stop or not on attribute failure */' + '\n'
file__pase_cli_async_h += '#define SQL400_ONERR_CONT 1' + '\n'
file__pase_cli_async_h += '#define SQL400_ONERR_STOP 2' + '\n'
file__pase_cli_async_h += '/* normal attributes */' + '\n'
file__pase_cli_async_h += '#define SQL400_FLAG_IMMED 0' + '\n'
file__pase_cli_async_h += '/* post connect attributes */' + '\n'
file__pase_cli_async_h += '#define SQL400_FLAG_POST_CONNECT 1' + '\n'
file__pase_cli_async_h += '#define SQL400_ATTR_CONN_CHGCURLIB 424201' + '\n'
file__pase_cli_async_h += '#define SQL400_ATTR_CONN_CHGLIBL 424202' + '\n'
file__pase_cli_async_h += 'typedef struct SQL400AttrStruct {' + '\n'
file__pase_cli_async_h += ' SQLINTEGER scope; /* - scope - SQL_HANDLE_ENV|DBC|SRTMT|DESC */' + '\n'
file__pase_cli_async_h += ' SQLHANDLE hndl; /* ecso - hndl - CLI handle */' + '\n'
file__pase_cli_async_h += ' SQLINTEGER attrib; /* ecso - attrib - CLI attribute */' + '\n'
file__pase_cli_async_h += ' SQLPOINTER vParam; /* ecso - vParam - ptr to CLI value */' + '\n'
file__pase_cli_async_h += ' SQLINTEGER inlen; /* ecs - inlen - len CLI value (string) */' + '\n'
file__pase_cli_async_h += ' SQLINTEGER sqlrc; /* - sqlrc - sql return code */' + '\n'
file__pase_cli_async_h += ' SQLINTEGER onerr; /* - onerr - SQL400_ONERR_xxx */' + '\n'
file__pase_cli_async_h += ' SQLINTEGER flag; /* - flag - SQL400_FLAG_xxx */' + '\n'
file__pase_cli_async_h += '} SQL400AttrStruct;' + '\n'
file__pase_cli_async_h += '/* Use:' + '\n'
file__pase_cli_async_h += ' * SQL400Execute( ..., SQLPOINTER parms, SQLPOINTER desc_parms)' + '\n'
file__pase_cli_async_h += ' * SQL400Fetch (..., SQLPOINTER desc_cols)' + '\n'
file__pase_cli_async_h += ' * CTOR:' + '\n'
file__pase_cli_async_h += ' * SQL400Describe' + '\n'
file__pase_cli_async_h += ' * SQL400AddCVar' + '\n'
file__pase_cli_async_h += ' * Struct:' + '\n'
file__pase_cli_async_h += ' * SQL400ParamStruct' + '\n'
file__pase_cli_async_h += ' * SQL400DescribeStruct' + '\n'
file__pase_cli_async_h += ' * p - SQLDescribeParam' + '\n'
file__pase_cli_async_h += ' * c - SQLDescribeCol' + '\n'
file__pase_cli_async_h += ' */' + '\n'
file__pase_cli_async_h += '#define SQL400_DESC_PARM 0' + '\n'
file__pase_cli_async_h += '#define SQL400_DESC_COL 1' + '\n'
file__pase_cli_async_h += '#define SQL400_PARM_IO_FILE 42' + '\n'
file__pase_cli_async_h += 'typedef struct SQL400ParamStruct {' + '\n'
file__pase_cli_async_h += ' SQLSMALLINT icol; /* icol - param number (in) */' + '\n'
file__pase_cli_async_h += ' SQLSMALLINT inOutType; /* inOutType - sql C in/out flag (in) */' + '\n'
file__pase_cli_async_h += ' SQLSMALLINT pfSqlCType; /* pfSqlCType - sql C data type (in) */' + '\n'
file__pase_cli_async_h += ' SQLPOINTER pfSqlCValue; /* pfSqlCValue - sql C ptr to data (out) */' + '\n'
file__pase_cli_async_h += ' SQLINTEGER * indPtr; /* indPtr - sql strlen/ind (out) */' + '\n'
file__pase_cli_async_h += '} SQL400ParamStruct;' + '\n'
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += 'typedef struct SQL400DescStruct {' + '\n'
file__pase_cli_async_h += ' SQLSMALLINT itype; /* - itype - descr col/parm (out) */' + '\n'
file__pase_cli_async_h += ' SQLSMALLINT icol; /* pc - icol - column number (in) */' + '\n'
file__pase_cli_async_h += ' SQLCHAR * szColName; /* c - szColName - column name ptr (out) */' + '\n'
file__pase_cli_async_h += ' SQLSMALLINT cbColNameMax; /* c - cbColNameMax - name max len (in) */' + '\n'
file__pase_cli_async_h += ' SQLSMALLINT pcbColName; /* c - pcbColName - name size len (out) */' + '\n'
file__pase_cli_async_h += ' SQLSMALLINT pfSqlType; /* pc - pfSqlType - sql data type (out) */' + '\n'
file__pase_cli_async_h += ' SQLINTEGER pcbColDef; /* pc - pcbColDef - sql size column (out) */' + '\n'
file__pase_cli_async_h += ' SQLSMALLINT pibScale; /* pc - pibScale - decimal digits (out) */' + '\n'
file__pase_cli_async_h += ' SQLSMALLINT pfNullable; /* pc - pfNullable - null allowed (out) */' + '\n'
file__pase_cli_async_h += ' SQLCHAR bfColName[1024]; /* c - bfColName - column name buf (out) */' + '\n'
file__pase_cli_async_h += '} SQL400DescStruct;' + '\n'
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += '/* special SQL400 aggregate functions */' + '\n'
file__pase_cli_async_h += '/* do common work for language driver */' + '\n'
file__pase_cli_async_h += '/* composite calls to CLI also async */' + '\n'
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += PaseCliOnly400_h_proto
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += '/* ===================================================' + '\n'
file__pase_cli_async_h += ' * NORMAL CLI interfaces' + '\n'
file__pase_cli_async_h += ' * ===================================================' + '\n'
file__pase_cli_async_h += ' */' + '\n'
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += '/* === sqlcli.h -- normal CLI interfaces (copy) === ' + '\n'
file__pase_cli_async_h += PaseCliAny_h_proto
file__pase_cli_async_h += ' * === sqlcli.h === */' + '\n'
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += '/* ===================================================' + '\n'
file__pase_cli_async_h += ' * ASYNC CLI interfaces' + '\n'
file__pase_cli_async_h += ' * ===================================================' + '\n'
file__pase_cli_async_h += ' */' + '\n'
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += '/* choose either callback or join */' + '\n'
file__pase_cli_async_h += '/* following structures returned */' + '\n'
file__pase_cli_async_h += '/* caller must free return structure */' + '\n'
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += PaseCliAsync_h_struct + '\n'
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += '/* join async thread */' + '\n'
file__pase_cli_async_h += '/* flag: */' + '\n'
file__pase_cli_async_h += '/* SQL400_FLAG_JOIN_WAIT */' + '\n'
file__pase_cli_async_h += '/* - block until complete */' + '\n'
file__pase_cli_async_h += '/* SQL400_FLAG_JOIN_NO_WAIT */' + '\n'
file__pase_cli_async_h += '/* - no block, NULL still executing */' + '\n'
file__pase_cli_async_h += '#define SQL400_FLAG_JOIN_WAIT 0' + '\n'
file__pase_cli_async_h += '#define SQL400_FLAG_JOIN_NO_WAIT 1' + '\n'
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += PaseCliAsync_h_proto_join
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += '/* start an async call to DB2 CLI */' + '\n'
file__pase_cli_async_h += '/* choose either callback or join */' + '\n'
file__pase_cli_async_h += '/* for results returned. */' + '\n'
file__pase_cli_async_h += '/* sqlrc returned in structure. */' + '\n'
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += PaseCliAsync_h_proto_async
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += '/* ===================================================' + '\n'
file__pase_cli_async_h += ' * ILE CLI interfaces' + '\n'
file__pase_cli_async_h += ' * ===================================================' + '\n'
file__pase_cli_async_h += ' */' + '\n'
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += PaseCliILE_h_proto
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += '/* ===================================================' + '\n'
file__pase_cli_async_h += ' * LIBDB400.A CLI interfaces (PASE old CLI driver)' + '\n'
file__pase_cli_async_h += ' * ===================================================' + '\n'
file__pase_cli_async_h += ' */' + '\n'
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += PaseCliLibDB400_h_proto
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += '/* ===================================================' + '\n'
file__pase_cli_async_h += ' * trace dump' + '\n'
file__pase_cli_async_h += ' * ===================================================' + '\n'
file__pase_cli_async_h += ' */' + '\n'
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += PaseCliDump_h_proto
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += '/* ===================================================' + '\n'
file__pase_cli_async_h += ' * INTERNAL USE' + '\n'
file__pase_cli_async_h += ' * ===================================================' + '\n'
file__pase_cli_async_h += ' */' + '\n'
file__pase_cli_async_h += '#ifndef SQL_ATTR_SERVERMODE_SUBSYSTEM' + '\n'
file__pase_cli_async_h += '#define SQL_ATTR_SERVERMODE_SUBSYSTEM 10204' + '\n'
file__pase_cli_async_h += '#endif' + '\n'
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += PaseCliCustom_h_proto
file__pase_cli_async_h += 'SQLRETURN custom_SQLSetEnvCCSID( SQLHANDLE env, int myccsid);' + '\n'
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += '' + '\n'
file__pase_cli_async_h += '#ifdef __cplusplus ' + '\n'
file__pase_cli_async_h += '}' + '\n'
file__pase_cli_async_h += '#endif /* __cplusplus */' + '\n'
file__pase_cli_async_h += '#endif /* _PASECLIASYNC_H */' + '\n'
with open('PaseCliAsync.h', 'w') as text_file:
text_file.write(file_PaseCliAsync_h)
file_libdb400_exp = ''
file_libdb400_exp += '#!libdb400.a(shr.o)' + '\n'
file_libdb400_exp += '' + '\n'
file_libdb400_exp += '' + '\n'
file_libdb400_exp += libdb400_exp
file_libdb400_exp += '' + '\n'
file_libdb400_exp += '' + '\n'
file_libdb400_exp += 'dev_dump' + '\n'
file_libdb400_exp += 'dev_go' + '\n'
file_libdb400_exp += 'printf_key' + '\n'
file_libdb400_exp += 'printf_buffer' + '\n'
file_libdb400_exp += 'printf_clear' + '\n'
file_libdb400_exp += 'printf_format' + '\n'
file_libdb400_exp += 'printf_hexdump' + '\n'
file_libdb400_exp += 'printf_stack' + '\n'
file_libdb400_exp += 'printf_script' + '\n'
file_libdb400_exp += 'printf_script_include' + '\n'
file_libdb400_exp += 'printf_script_exclude' + '\n'
file_libdb400_exp += 'printf_script_clear' + '\n'
file_libdb400_exp += 'printf_force_SIGQUIT' + '\n'
file_libdb400_exp += 'printf_sqlrc_status' + '\n'
file_libdb400_exp += 'printf_sqlrc_head_foot' + '\n'
file_libdb400_exp += 'sprintf_format' + '\n'
file_libdb400_exp += '' + '\n'
file_libdb400_exp += '' + '\n'
with open('libdb400.exp', 'w') as text_file:
text_file.write(file_libdb400_exp) |
VERSION = (0, 1, 0)
__author__ = 'Ivan Sushkov <comeuplater>'
__version__ = '.'.join(str(x) for x in VERSION)
| version = (0, 1, 0)
__author__ = 'Ivan Sushkov <comeuplater>'
__version__ = '.'.join((str(x) for x in VERSION)) |
def zero_matrix(matrix):
points = []
for row in range(len(matrix)):
for col in range(len(matrix[row])):
val = matrix[row][col]
if val == 0:
points.append((row, col))
for point in points:
update_row(matrix, point[0])
update_col(matrix, point[1])
def update_col(matrix, col):
for row in range(len(matrix)):
matrix[row][col] = 0
def update_row(matrix, row):
for col in range(len(matrix[row])):
matrix[row][col] = 0
matrix = [[4, 3, 1, 0], [6, 1, 2, 5], [8, 0, 1, 7], [5, 2, 1, 1]]
zero_matrix(matrix)
print(matrix)
| def zero_matrix(matrix):
points = []
for row in range(len(matrix)):
for col in range(len(matrix[row])):
val = matrix[row][col]
if val == 0:
points.append((row, col))
for point in points:
update_row(matrix, point[0])
update_col(matrix, point[1])
def update_col(matrix, col):
for row in range(len(matrix)):
matrix[row][col] = 0
def update_row(matrix, row):
for col in range(len(matrix[row])):
matrix[row][col] = 0
matrix = [[4, 3, 1, 0], [6, 1, 2, 5], [8, 0, 1, 7], [5, 2, 1, 1]]
zero_matrix(matrix)
print(matrix) |
Aa,Va=input().split()
Ab,Vb=input().split()
Aa,Va,Ab,Vb=int(Aa),int(Va),int(Ab),int(Vb)
Fb=Ab-Vb
while Fb>0 and Va>0:
Vb+=1
Va-=1
Fb-=1
print(Va,Vb)
| (aa, va) = input().split()
(ab, vb) = input().split()
(aa, va, ab, vb) = (int(Aa), int(Va), int(Ab), int(Vb))
fb = Ab - Vb
while Fb > 0 and Va > 0:
vb += 1
va -= 1
fb -= 1
print(Va, Vb) |
class NoGeometry(RuntimeError):
pass
class NoSuperelements(RuntimeError):
pass
| class Nogeometry(RuntimeError):
pass
class Nosuperelements(RuntimeError):
pass |
a = 1
b = 2
c =2
a = 2
class info():
def __init__(self):
self.color="red"
| a = 1
b = 2
c = 2
a = 2
class Info:
def __init__(self):
self.color = 'red' |
# SPDX-FileCopyrightText: no
# SPDX-License-Identifier: CC0-1.0
#
# Stubs for part of the Python API from libcalamares
# (although the **actual** API is presented through
# Boost::Python, not as a bare C-extension) so that
# pylint doesn't complain about libcalamares internals.
VERSION_SHORT="1.0"
| version_short = '1.0' |
'''
Sorting is useful as the first step in many different tasks. The most common task is to make finding things easier,
but there are other uses as well. In this case, it will make it easier to determine which pair or pairs of elements
have the smallest absolute difference between them.
For example, if you've got the list [5, 2, 3, 4, 1], sort it as [1, 2, 3, 4, 5] to see that several pairs
have the minimum difference of 1: [(1, 2), (2, 3), (3, 4), (4, 5)].
The return array would be [1, 2, 2, 3, 3, 4, 4, 5].
Given a list of unsorted integers, , find the pair of elements that have the smallest absolute difference between them.
If there are multiple pairs, find them all.
'''
def closestNumbers(arr):
arr = sorted(list(set(arr)))
m = None
ans = []
for i in range(1, len(arr)):
diff = arr[i]-arr[i-1]
if m is None or m>diff:
ans = [arr[i-1], arr[i]]
m = diff
elif m==diff:
ans.append(arr[i-1])
ans.append(arr[i])
return ans
if __name__ == '__main__':
data = [
[5, 2, 3, 4, 1],
]
for l in data:
print(closestNumbers(l)) | """
Sorting is useful as the first step in many different tasks. The most common task is to make finding things easier,
but there are other uses as well. In this case, it will make it easier to determine which pair or pairs of elements
have the smallest absolute difference between them.
For example, if you've got the list [5, 2, 3, 4, 1], sort it as [1, 2, 3, 4, 5] to see that several pairs
have the minimum difference of 1: [(1, 2), (2, 3), (3, 4), (4, 5)].
The return array would be [1, 2, 2, 3, 3, 4, 4, 5].
Given a list of unsorted integers, , find the pair of elements that have the smallest absolute difference between them.
If there are multiple pairs, find them all.
"""
def closest_numbers(arr):
arr = sorted(list(set(arr)))
m = None
ans = []
for i in range(1, len(arr)):
diff = arr[i] - arr[i - 1]
if m is None or m > diff:
ans = [arr[i - 1], arr[i]]
m = diff
elif m == diff:
ans.append(arr[i - 1])
ans.append(arr[i])
return ans
if __name__ == '__main__':
data = [[5, 2, 3, 4, 1]]
for l in data:
print(closest_numbers(l)) |
def _combinators(_handle, items, n):
if n==0:
yield []
return
for i, item in enumerate(items):
this_one = [ item ]
for cc in _combinators(_handle, _handle(items, i), n-1):
yield this_one + cc
def combinations(items, n):
''' take n distinct items, order matters '''
def skipIthItem(items, i):
return items[:i] + items[i+1:]
return _combinators(skipIthItem, items, n)
def uniqueCombinations(items, n):
''' take n distinct items, order is irrelevant '''
def afterIthItem(items, i):
return items[i+1:]
return _combinators(afterIthItem, items, n)
def selections(items, n):
''' take n (not necessarily distinct) items, order matters '''
def keepAllItems(items, i):
return items
return _combinators(keepAllItems, items, n)
def permutations(items):
''' take all items, order matters '''
return combinations(items, len(items))
| def _combinators(_handle, items, n):
if n == 0:
yield []
return
for (i, item) in enumerate(items):
this_one = [item]
for cc in _combinators(_handle, _handle(items, i), n - 1):
yield (this_one + cc)
def combinations(items, n):
""" take n distinct items, order matters """
def skip_ith_item(items, i):
return items[:i] + items[i + 1:]
return _combinators(skipIthItem, items, n)
def unique_combinations(items, n):
""" take n distinct items, order is irrelevant """
def after_ith_item(items, i):
return items[i + 1:]
return _combinators(afterIthItem, items, n)
def selections(items, n):
""" take n (not necessarily distinct) items, order matters """
def keep_all_items(items, i):
return items
return _combinators(keepAllItems, items, n)
def permutations(items):
""" take all items, order matters """
return combinations(items, len(items)) |
'''6. Write a Python program to count the number of equal numbers from three given integers.
Sample Output:
3
2
0
3'''
def count(num):
if num[0]==num[1] and num[0]==num[2]:
ans = 3
elif num[0]==num[1] or num[1]==num[2] or num[0]==num[2]:
ans = 2
else:
ans = 0
return ans
print(count((1, 1, 1)))
print(count((1, 2, 2)))
print(count((-1, -2, -3)))
print(count((-1, -1, -1))) | """6. Write a Python program to count the number of equal numbers from three given integers.
Sample Output:
3
2
0
3"""
def count(num):
if num[0] == num[1] and num[0] == num[2]:
ans = 3
elif num[0] == num[1] or num[1] == num[2] or num[0] == num[2]:
ans = 2
else:
ans = 0
return ans
print(count((1, 1, 1)))
print(count((1, 2, 2)))
print(count((-1, -2, -3)))
print(count((-1, -1, -1))) |
#!/usr/bin/env python3
"""Lists and tuples."""
MONTHS_TUPLE = ('January', 'February', 'March',
'April', 'May', 'June', 'July',
'August', 'September', 'October', 'November', 'December')
MONTHS_LIST = list(MONTHS_TUPLE)
print('MONTHS_TUPLE is {}.'.format(type(MONTHS_TUPLE)))
print('MONTHS_LIST is {}.'.format(type(MONTHS_LIST)))
ANIMALS_LIST = ['toad', 'lion', 'seal']
ANIMALS_TUPLE = tuple(ANIMALS_LIST)
print('ANIMALS_LIST is {}.'.format(type(ANIMALS_LIST)))
print('ANIMALS_TUPLE is {}.'.format(type(ANIMALS_TUPLE)))
| """Lists and tuples."""
months_tuple = ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December')
months_list = list(MONTHS_TUPLE)
print('MONTHS_TUPLE is {}.'.format(type(MONTHS_TUPLE)))
print('MONTHS_LIST is {}.'.format(type(MONTHS_LIST)))
animals_list = ['toad', 'lion', 'seal']
animals_tuple = tuple(ANIMALS_LIST)
print('ANIMALS_LIST is {}.'.format(type(ANIMALS_LIST)))
print('ANIMALS_TUPLE is {}.'.format(type(ANIMALS_TUPLE))) |
class Sources:
'''
News class to define News sources Objects
'''
def __init__(self, id, name, description):
self.id = id
self.name = name
self.description = description
class Articles:
'''
Headlines to define News articles class
'''
def __init__(self, source, author, title, description, publishedAt, url, urlToImage):
self.source = source
self.author = author
self.title = title
self.description = description
self.publishedAt = publishedAt
self.url = url
self.urlToImage = urlToImage
| class Sources:
"""
News class to define News sources Objects
"""
def __init__(self, id, name, description):
self.id = id
self.name = name
self.description = description
class Articles:
"""
Headlines to define News articles class
"""
def __init__(self, source, author, title, description, publishedAt, url, urlToImage):
self.source = source
self.author = author
self.title = title
self.description = description
self.publishedAt = publishedAt
self.url = url
self.urlToImage = urlToImage |
# LEETCODE 121: Best Time to Buy and Sell Stock
#
# https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
#
# Say you have an array for which the ith element is the price of a given stock on day i.
#
# If you were only permitted to complete at most one transaction
# (i.e., buy one and sell one share of the stock),
# design an algorithm to find the maximum profit.
#
# Example 1:
#
# Input: [7,1,5,3,6,4]
# Output: 7
#
# Example 2:
#
# Input: [7,6,4,3,1]
# Output: 0
def max_profit(prices):
# sanity checks
count = len(prices)
if count < 2:
return 0
# at this point, we have at least 2 data points in prices
# what we return
profit = 0
# compute differences list
diff = [0]
for i in range(1, count):
diff.append(prices[i] - prices[i-1])
# debug
print('Prices:', prices)
print('Diff:', diff)
# consume differences list
is_buy = True
for i,_ in enumerate(diff):
if is_buy:
if (i == 0 and diff[1] > 0) or (
i > 0 and
i < count - 2 and
diff[i-1] >= 0 and
diff[i+1] > 0 and
diff[i] <= 0):
print('Buy:', prices[i])
profit -= prices[i]
is_buy = False
else:
if (i == count - 1) or (
i < count - 1 and
diff[i-1] <= 0 and
diff[i+1] < 0 and
diff[i] > 0):
#print('Sell:', prices[i])
profit += prices[i]
is_buy = True
# finally return
return profit
####
# test cases
prices = [7,1,5,3,6,4]
profit = max_profit(prices)
print('prices =', prices, ', profit =', profit)
prices = [7,6,4,3,1]
profit = max_profit(prices)
print('prices =', prices, ', profit =', profit) | def max_profit(prices):
count = len(prices)
if count < 2:
return 0
profit = 0
diff = [0]
for i in range(1, count):
diff.append(prices[i] - prices[i - 1])
print('Prices:', prices)
print('Diff:', diff)
is_buy = True
for (i, _) in enumerate(diff):
if is_buy:
if i == 0 and diff[1] > 0 or (i > 0 and i < count - 2 and (diff[i - 1] >= 0) and (diff[i + 1] > 0) and (diff[i] <= 0)):
print('Buy:', prices[i])
profit -= prices[i]
is_buy = False
elif i == count - 1 or (i < count - 1 and diff[i - 1] <= 0 and (diff[i + 1] < 0) and (diff[i] > 0)):
profit += prices[i]
is_buy = True
return profit
prices = [7, 1, 5, 3, 6, 4]
profit = max_profit(prices)
print('prices =', prices, ', profit =', profit)
prices = [7, 6, 4, 3, 1]
profit = max_profit(prices)
print('prices =', prices, ', profit =', profit) |
def test_view(invoke, secret):
invoke(['decrypt'])
decrypted = invoke(['view', secret.encrypted.as_posix()])
plaintext = secret.decrypted.read_text().splitlines()
assert decrypted == plaintext
| def test_view(invoke, secret):
invoke(['decrypt'])
decrypted = invoke(['view', secret.encrypted.as_posix()])
plaintext = secret.decrypted.read_text().splitlines()
assert decrypted == plaintext |
# Copyright (c) 2015 OpenStack Foundation.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# Pipline Table numbers
INGRESS_CLASSIFICATION_DISPATCH_TABLE = 0
EGRESS_CONNTRACK_TABLE = 3
EGRESS_SECURITY_GROUP_TABLE = 6
SERVICES_CLASSIFICATION_TABLE = 9
ARP_TABLE = 10
DHCP_TABLE = 11
INGRESS_NAT_TABLE = 15
L2_LOOKUP_TABLE = 17
L3_LOOKUP_TABLE = 20
L3_PROACTIVE_LOOKUP_TABLE = 25
EGRESS_NAT_TABLE = 30
EGRESS_TABLE = 64
CANARY_TABLE = 200
INGRESS_CONNTRACK_TABLE = 72
INGRESS_SECURITY_GROUP_TABLE = 77
INGRESS_DISPATCH_TABLE = 78
# Flow Priorities
PRIORITY_DEFAULT = 1
PRIORITY_LOW = 50
PRIORITY_MEDIUM = 100
PRIORITY_HIGH = 200
PRIORITY_VERY_HIGH = 300
PRIORITY_CT_STATE = 65534
# Connection Track flags
CT_STATE_NEW = 0x01
CT_STATE_EST = 0x02
CT_STATE_REL = 0x04
CT_STATE_RPL = 0x08
CT_STATE_INV = 0x10
CT_STATE_TRK = 0x20
CT_FLAG_COMMIT = 1
# Register match
METADATA_REG = 0x80000408
CT_ZONE_REG = 0x1d402
DRAGONFLOW_DEFAULT_BRIDGE = 'br-int'
"""
Cookie Mask
global cookie is used by flows of all table, but local cookie is used
by flows of a small part of table. In order to avoid conflict,
global cookies should not overlapped with each other, but local cookies
could be overlapped for saving space of cookie.
all cookie's mask should be kept here to avoid conflict.
"""
GLOBAL_AGING_COOKIE_MASK = 0x1
SECURITY_GROUP_RULE_COOKIE_MASK = 0x1fffffffe
SECURITY_GROUP_RULE_COOKIE_SHIFT_LEN = 1
GLOBAL_INIT_AGING_COOKIE = 0x1
| ingress_classification_dispatch_table = 0
egress_conntrack_table = 3
egress_security_group_table = 6
services_classification_table = 9
arp_table = 10
dhcp_table = 11
ingress_nat_table = 15
l2_lookup_table = 17
l3_lookup_table = 20
l3_proactive_lookup_table = 25
egress_nat_table = 30
egress_table = 64
canary_table = 200
ingress_conntrack_table = 72
ingress_security_group_table = 77
ingress_dispatch_table = 78
priority_default = 1
priority_low = 50
priority_medium = 100
priority_high = 200
priority_very_high = 300
priority_ct_state = 65534
ct_state_new = 1
ct_state_est = 2
ct_state_rel = 4
ct_state_rpl = 8
ct_state_inv = 16
ct_state_trk = 32
ct_flag_commit = 1
metadata_reg = 2147484680
ct_zone_reg = 119810
dragonflow_default_bridge = 'br-int'
"\nCookie Mask\nglobal cookie is used by flows of all table, but local cookie is used\nby flows of a small part of table. In order to avoid conflict,\nglobal cookies should not overlapped with each other, but local cookies\ncould be overlapped for saving space of cookie.\nall cookie's mask should be kept here to avoid conflict.\n"
global_aging_cookie_mask = 1
security_group_rule_cookie_mask = 8589934590
security_group_rule_cookie_shift_len = 1
global_init_aging_cookie = 1 |
{
'variables':
{
'external_libmediaserver%' : '<!(echo $LIBMEDIASERVER)',
'external_libmediaserver_include_dirs%' : '<!(echo $LIBMEDIASERVER_INCLUDE)',
},
"targets":
[
{
"target_name": "medooze-audio-codecs",
"cflags":
[
"-march=native",
"-fexceptions",
"-O3",
"-g",
"-Wno-unused-function -Wno-comment",
"-DSPX_RESAMPLE_EXPORT= -DRANDOM_PREFIX=mcu -DOUTSIDE_SPEEX -DFLOATING_POINT",
#"-O0",
#"-fsanitize=address"
],
"cflags_cc":
[
"-fexceptions",
"-std=c++17",
"-O3",
"-g",
"-Wno-unused-function",
"-DSPX_RESAMPLE_EXPORT= -DRANDOM_PREFIX=mcu -DOUTSIDE_SPEEX -DFLOATING_POINT",
"-faligned-new",
#"-O0",
#"-fsanitize=address,leak"
],
"include_dirs" :
[
'/usr/include/nodejs/',
"<!(node -e \"require('nan')\")"
],
"ldflags" : [" -lpthread -lresolv"],
"link_settings":
{
'libraries': ["-lpthread -lpthread -lresolv -lavcodec -lspeex -lopus"]
},
"sources":
[
"src/audio-codecs_wrap.cxx",
],
"conditions":
[
[
"external_libmediaserver == ''",
{
"include_dirs" :
[
'media-server/include',
'media-server/src',
'media-server/ext/crc32c/include',
'media-server/ext/libdatachannels/src',
'media-server/ext/libdatachannels/src/internal',
"media-server/src/g711",
"media-server/src/g722",
"media-server/src/gsm",
"media-server/src/aac",
"media-server/src/opus",
"media-server/src/speex",
"media-server/src/nelly",
],
"sources":
[
"media-server/src/audioencoder.cpp",
"media-server/src/audiodecoder.cpp",
"media-server/src/AudioCodecFactory.cpp",
"media-server/src/AudioPipe.cpp",
"media-server/src/audiotransrater.cpp",
"media-server/src/EventLoop.cpp",
"media-server/src/MediaFrameListenerBridge.cpp",
"media-server/src/rtp/DependencyDescriptor.cpp",
"media-server/src/rtp/RTPPacket.cpp",
"media-server/src/rtp/RTPPayload.cpp",
"media-server/src/rtp/RTPHeader.cpp",
"media-server/src/rtp/RTPHeaderExtension.cpp",
"media-server/src/rtp/RTPMap.cpp",
"media-server/src/g711/pcmucodec.cpp",
"media-server/src/g711/pcmacodec.cpp",
"media-server/src/g711/g711.cpp",
"media-server/src/g722/g722_encode.c",
"media-server/src/g722/g722_decode.c",
"media-server/src/g722/g722codec.cpp",
"media-server/src/gsm/gsmcodec.cpp",
"media-server/src/aac/aacencoder.cpp",
"media-server/src/aac/aacdecoder.cpp",
"media-server/src/opus/opusdecoder.cpp",
"media-server/src/opus/opusencoder.cpp",
"media-server/src/speex/speexcodec.cpp",
"media-server/src/speex/resample.c",
"media-server/src/nelly/NellyCodec.cpp",
"media-server/src/opus/opusdepacketizer.cpp",
"media-server/src/rtp/RTPDepacketizer.cpp",
"media-server/src/rtp/RTPIncomingMediaStreamDepacketizer.cpp",
],
"conditions" : [
['OS=="mac"', {
"xcode_settings": {
"CLANG_CXX_LIBRARY": "libc++",
"CLANG_CXX_LANGUAGE_STANDARD": "c++17",
"OTHER_CFLAGS": [ "-Wno-aligned-allocation-unavailable","-march=native"]
},
}]
]
},
{
"libraries" : [ "<(external_libmediaserver)" ],
"include_dirs" : [ "<@(external_libmediaserver_include_dirs)" ],
'conditions':
[
['OS=="linux"', {
"ldflags" : [" -Wl,-Bsymbolic "],
}],
['OS=="mac"', {
"xcode_settings": {
"CLANG_CXX_LIBRARY": "libc++",
"CLANG_CXX_LANGUAGE_STANDARD": "c++17",
"OTHER_CFLAGS": [ "-Wno-aligned-allocation-unavailable","-march=native"]
},
}],
]
}
]
]
}
]
}
| {'variables': {'external_libmediaserver%': '<!(echo $LIBMEDIASERVER)', 'external_libmediaserver_include_dirs%': '<!(echo $LIBMEDIASERVER_INCLUDE)'}, 'targets': [{'target_name': 'medooze-audio-codecs', 'cflags': ['-march=native', '-fexceptions', '-O3', '-g', '-Wno-unused-function -Wno-comment', '-DSPX_RESAMPLE_EXPORT= -DRANDOM_PREFIX=mcu -DOUTSIDE_SPEEX -DFLOATING_POINT'], 'cflags_cc': ['-fexceptions', '-std=c++17', '-O3', '-g', '-Wno-unused-function', '-DSPX_RESAMPLE_EXPORT= -DRANDOM_PREFIX=mcu -DOUTSIDE_SPEEX -DFLOATING_POINT', '-faligned-new'], 'include_dirs': ['/usr/include/nodejs/', '<!(node -e "require(\'nan\')")'], 'ldflags': [' -lpthread -lresolv'], 'link_settings': {'libraries': ['-lpthread -lpthread -lresolv -lavcodec -lspeex -lopus']}, 'sources': ['src/audio-codecs_wrap.cxx'], 'conditions': [["external_libmediaserver == ''", {'include_dirs': ['media-server/include', 'media-server/src', 'media-server/ext/crc32c/include', 'media-server/ext/libdatachannels/src', 'media-server/ext/libdatachannels/src/internal', 'media-server/src/g711', 'media-server/src/g722', 'media-server/src/gsm', 'media-server/src/aac', 'media-server/src/opus', 'media-server/src/speex', 'media-server/src/nelly'], 'sources': ['media-server/src/audioencoder.cpp', 'media-server/src/audiodecoder.cpp', 'media-server/src/AudioCodecFactory.cpp', 'media-server/src/AudioPipe.cpp', 'media-server/src/audiotransrater.cpp', 'media-server/src/EventLoop.cpp', 'media-server/src/MediaFrameListenerBridge.cpp', 'media-server/src/rtp/DependencyDescriptor.cpp', 'media-server/src/rtp/RTPPacket.cpp', 'media-server/src/rtp/RTPPayload.cpp', 'media-server/src/rtp/RTPHeader.cpp', 'media-server/src/rtp/RTPHeaderExtension.cpp', 'media-server/src/rtp/RTPMap.cpp', 'media-server/src/g711/pcmucodec.cpp', 'media-server/src/g711/pcmacodec.cpp', 'media-server/src/g711/g711.cpp', 'media-server/src/g722/g722_encode.c', 'media-server/src/g722/g722_decode.c', 'media-server/src/g722/g722codec.cpp', 'media-server/src/gsm/gsmcodec.cpp', 'media-server/src/aac/aacencoder.cpp', 'media-server/src/aac/aacdecoder.cpp', 'media-server/src/opus/opusdecoder.cpp', 'media-server/src/opus/opusencoder.cpp', 'media-server/src/speex/speexcodec.cpp', 'media-server/src/speex/resample.c', 'media-server/src/nelly/NellyCodec.cpp', 'media-server/src/opus/opusdepacketizer.cpp', 'media-server/src/rtp/RTPDepacketizer.cpp', 'media-server/src/rtp/RTPIncomingMediaStreamDepacketizer.cpp'], 'conditions': [['OS=="mac"', {'xcode_settings': {'CLANG_CXX_LIBRARY': 'libc++', 'CLANG_CXX_LANGUAGE_STANDARD': 'c++17', 'OTHER_CFLAGS': ['-Wno-aligned-allocation-unavailable', '-march=native']}}]]}, {'libraries': ['<(external_libmediaserver)'], 'include_dirs': ['<@(external_libmediaserver_include_dirs)'], 'conditions': [['OS=="linux"', {'ldflags': [' -Wl,-Bsymbolic ']}], ['OS=="mac"', {'xcode_settings': {'CLANG_CXX_LIBRARY': 'libc++', 'CLANG_CXX_LANGUAGE_STANDARD': 'c++17', 'OTHER_CFLAGS': ['-Wno-aligned-allocation-unavailable', '-march=native']}}]]}]]}]} |
"""
Define constants for Nary task.
"""
EMB_INIT_RANGE = 1.0
# vocab
PAD_TOKEN = '<PAD>'
PAD_ID = 0
UNK_TOKEN = '<UNK>'
UNK_ID = 1
VOCAB_PREFIX = [PAD_TOKEN, UNK_TOKEN]
POS_TO_ID = {PAD_TOKEN: 0, UNK_TOKEN: 1, 'PRP': 2, 'NN': 3, 'VBZ': 4, '``': 5, '-LRB-': 6, 'JJR': 7, 'LS': 8, 'MD': 9, 'JJ': 10, 'PRP$': 11, 'RB': 12, "''": 13, 'RP': 14, 'VBP': 15, 'IN': 16, 'CD': 17, 'EX': 18, 'WP$': 19, 'NNS': 20, 'WP': 21, 'VBN': 22, 'PDT': 23, ',': 24, '.': 25, 'NNPS': 26, 'JJS': 27, 'NNP': 28, 'TO': 29, 'WDT': 30, 'SYM': 31, 'POS': 32, 'VBG': 33, 'RBS': 34, 'FW': 35, 'VB': 36, 'RBR': 37, 'CC': 38, 'WRB': 39, 'DT': 40, 'VBD': 41, '-RRB-': 42, ':': 43}
DEPREL_TO_ID = {PAD_TOKEN: 0, UNK_TOKEN: 1, 'mwe': 2, 'xcomp': 3, 'next': 4, 'prepc': 5, 'amod': 6, 'appos': 7, 'iobj': 8, 'cop': 9, 'hyphen': 10, 'pcomp': 11, 'preconj': 12, 'partmod': 13, 'prep': 14, 'dep': 15, 'csubjpass': 16, 'neg': 17, 'purpcl': 18, 'tmod': 19, 'poss': 20, 'cc': 21, 'complm': 22, 'infmod': 23, 'agent': 24, 'number': 25, 'acomp': 26, 'abbrev': 27, 'punct': 28, 'rel': 29, 'npadvmod': 30, 'possessive': 31, 'det': 32, 'nsubjpass': 33, 'prt': 34, 'nn': 35, 'quantmod': 36, 'advmod': 37, 'aux': 38, 'ccomp': 39, 'pobj': 40, 'parataxis': 41, 'nsubj': 42, 'expl': 43, 'dobj': 44, 'advcl': 45, 'auxpass': 46, 'predet': 47, 'num': 48, 'conj': 49, 'rcmod': 50, 'csubj': 51, 'self': 52}
DIRECTIONS = 1
NEGATIVE_LABEL = 'None'
LABEL_TO_ID = {'None': 0, 'resistance or non-response': 1, 'sensitivity': 2, 'response': 3, 'resistance': 4}
#LABEL_TO_ID = {'No': 0, 'Yes': 1}
INFINITY_NUMBER = 1e12
| """
Define constants for Nary task.
"""
emb_init_range = 1.0
pad_token = '<PAD>'
pad_id = 0
unk_token = '<UNK>'
unk_id = 1
vocab_prefix = [PAD_TOKEN, UNK_TOKEN]
pos_to_id = {PAD_TOKEN: 0, UNK_TOKEN: 1, 'PRP': 2, 'NN': 3, 'VBZ': 4, '``': 5, '-LRB-': 6, 'JJR': 7, 'LS': 8, 'MD': 9, 'JJ': 10, 'PRP$': 11, 'RB': 12, "''": 13, 'RP': 14, 'VBP': 15, 'IN': 16, 'CD': 17, 'EX': 18, 'WP$': 19, 'NNS': 20, 'WP': 21, 'VBN': 22, 'PDT': 23, ',': 24, '.': 25, 'NNPS': 26, 'JJS': 27, 'NNP': 28, 'TO': 29, 'WDT': 30, 'SYM': 31, 'POS': 32, 'VBG': 33, 'RBS': 34, 'FW': 35, 'VB': 36, 'RBR': 37, 'CC': 38, 'WRB': 39, 'DT': 40, 'VBD': 41, '-RRB-': 42, ':': 43}
deprel_to_id = {PAD_TOKEN: 0, UNK_TOKEN: 1, 'mwe': 2, 'xcomp': 3, 'next': 4, 'prepc': 5, 'amod': 6, 'appos': 7, 'iobj': 8, 'cop': 9, 'hyphen': 10, 'pcomp': 11, 'preconj': 12, 'partmod': 13, 'prep': 14, 'dep': 15, 'csubjpass': 16, 'neg': 17, 'purpcl': 18, 'tmod': 19, 'poss': 20, 'cc': 21, 'complm': 22, 'infmod': 23, 'agent': 24, 'number': 25, 'acomp': 26, 'abbrev': 27, 'punct': 28, 'rel': 29, 'npadvmod': 30, 'possessive': 31, 'det': 32, 'nsubjpass': 33, 'prt': 34, 'nn': 35, 'quantmod': 36, 'advmod': 37, 'aux': 38, 'ccomp': 39, 'pobj': 40, 'parataxis': 41, 'nsubj': 42, 'expl': 43, 'dobj': 44, 'advcl': 45, 'auxpass': 46, 'predet': 47, 'num': 48, 'conj': 49, 'rcmod': 50, 'csubj': 51, 'self': 52}
directions = 1
negative_label = 'None'
label_to_id = {'None': 0, 'resistance or non-response': 1, 'sensitivity': 2, 'response': 3, 'resistance': 4}
infinity_number = 1000000000000.0 |
def a(m,limit):
turn=len(m)
last_spoken = m[-1]
while turn < 2020:
turn += 1
try:
distance = list(reversed(m[:-1])).index(last_spoken)+1
except ValueError:
distance = 0
m.append(distance)
last_spoken = distance
return(m[-1])
def ab(m, limit):
d = dict()
for i, v in enumerate(m[:-1]):
d[v] = i + 1
turn=len(m)
last_spoken = m[-1]
while turn < limit:
if last_spoken in d:
distance = turn - d[last_spoken]
else:
distance = 0
d[last_spoken] = turn
turn += 1
last_spoken = distance
return(distance)
for limit in [2020, 30000000]:
print(ab([9,3,1,0,8,4],limit))
print(ab([0,3,6],limit))
print(ab([1,3,2],limit))
print(ab([2,1,3],limit))
print(ab([1,2,3],limit))
print(ab([2,3,1],limit))
print(ab([3,1,2],limit))
| def a(m, limit):
turn = len(m)
last_spoken = m[-1]
while turn < 2020:
turn += 1
try:
distance = list(reversed(m[:-1])).index(last_spoken) + 1
except ValueError:
distance = 0
m.append(distance)
last_spoken = distance
return m[-1]
def ab(m, limit):
d = dict()
for (i, v) in enumerate(m[:-1]):
d[v] = i + 1
turn = len(m)
last_spoken = m[-1]
while turn < limit:
if last_spoken in d:
distance = turn - d[last_spoken]
else:
distance = 0
d[last_spoken] = turn
turn += 1
last_spoken = distance
return distance
for limit in [2020, 30000000]:
print(ab([9, 3, 1, 0, 8, 4], limit))
print(ab([0, 3, 6], limit))
print(ab([1, 3, 2], limit))
print(ab([2, 1, 3], limit))
print(ab([1, 2, 3], limit))
print(ab([2, 3, 1], limit))
print(ab([3, 1, 2], limit)) |
# Title : TODO
# Objective : TODO
# Created by: Wenzurk
# Created on: 2018/2/10
# alien_0 = {'color': 'green', 'point': '5'}
# alien_1 = {'color': 'yellow', 'point': '10'}
# alien_2 = {'color': 'red', 'point': '15'}
#
# aliens = [alien_0, alien_1, alien_2]
#
# for alien in aliens:
# print(alien)
aliens = []
for alien_number in range(30):
new_alien = {'color': 'green', 'points': '5', 'speed': 'slow'}
aliens.append(new_alien)
for alien in aliens[0:3]:
if alien['color'] == 'green':
alien['color'] = 'yellow'
alien['speed'] = 'medium'
alien['points'] = 10
elif alien['color'] == 'yellow':
alien['color'] = 'red'
alien['speed'] = 'fast'
alien['points'] = 15
for alien in aliens[:5]:
print(alien)
print("...")
print("Total number of aliens: " + str(len(aliens))) | aliens = []
for alien_number in range(30):
new_alien = {'color': 'green', 'points': '5', 'speed': 'slow'}
aliens.append(new_alien)
for alien in aliens[0:3]:
if alien['color'] == 'green':
alien['color'] = 'yellow'
alien['speed'] = 'medium'
alien['points'] = 10
elif alien['color'] == 'yellow':
alien['color'] = 'red'
alien['speed'] = 'fast'
alien['points'] = 15
for alien in aliens[:5]:
print(alien)
print('...')
print('Total number of aliens: ' + str(len(aliens))) |
class Fruit:
def eat(self):
print("Eating..")
f=Fruit()
f.eat() | class Fruit:
def eat(self):
print('Eating..')
f = fruit()
f.eat() |
iterable = range(5) # range is the iterable
iterator = iter(iterable) # extract iterator from iterable
while True:
try:
n = next(iterator)
# Code inside "for" loop
print(n, end=" ")
n = 5 # Will be overridden by line 5 in next iteration
except StopIteration: # iterator signaled it's exhausted
break
print() # Code after "for" loop
| iterable = range(5)
iterator = iter(iterable)
while True:
try:
n = next(iterator)
print(n, end=' ')
n = 5
except StopIteration:
break
print() |
""" Write the pseudocode for a function which returns the highest perfect square which is less or equal to its parameter (a positive integer). Implement this in a programming language of your choice. """
def power(number):
x = 1
""" check if every square number going up from 1 fits. """
while x * x < number:
x = x + 1
""" when the square number goes over the limit roll back the result by 1. """
if x * x > number:
x = x - 1
return x
""" number to be checked <- input number
squared <- 1
while squared * squared < number to be checked
squared <- squared + 1
if squared * squared > number to be checked
squared <- squared - 1
output squared
O(N) complexity """
| """ Write the pseudocode for a function which returns the highest perfect square which is less or equal to its parameter (a positive integer). Implement this in a programming language of your choice. """
def power(number):
x = 1
' check if every square number going up from 1 fits. '
while x * x < number:
x = x + 1
' when the square number goes over the limit roll back the result by 1. '
if x * x > number:
x = x - 1
return x
' number to be checked <- input number\nsquared <- 1\n\nwhile squared * squared < number to be checked\n squared <- squared + 1\n\nif squared * squared > number to be checked\n squared <- squared - 1\n\noutput squared\n\nO(N) complexity ' |
#!/usr/bin/env python
# Copyright 2016 Cisco Systems, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
class TORClientException(Exception):
pass
class BasicTORClient(object):
def __init__(self, config):
pass
def get_int_counters(self):
return {}
def get_vni_counters(self, vni):
return {}
def get_vni_interface(self, vni, counters):
return None
def get_vni_for_vlan(self, vlans):
return []
def attach_tg_interfaces(self, network_vlans, switch_ports):
pass
def clear_nve(self):
pass
def clear_interface(self, vni):
pass
def close(self):
pass
def get_version(self):
return {}
| class Torclientexception(Exception):
pass
class Basictorclient(object):
def __init__(self, config):
pass
def get_int_counters(self):
return {}
def get_vni_counters(self, vni):
return {}
def get_vni_interface(self, vni, counters):
return None
def get_vni_for_vlan(self, vlans):
return []
def attach_tg_interfaces(self, network_vlans, switch_ports):
pass
def clear_nve(self):
pass
def clear_interface(self, vni):
pass
def close(self):
pass
def get_version(self):
return {} |
class dir:
misc = "misc/"
datasets = "datasets/"
kerasModels = misc + "kerasModels/"
autoencoders = kerasModels + 'autoencoder/'
@staticmethod
def get_autoencoder_dir_of_latent_size(latentSize):
return dir.autoencoders + "ae" + str(latentSize) + '/'
class dataset:
_directory = dir.datasets
_processedDir = _directory + "processed/"
_rawDir = _directory + "raw/"
_normDir = _directory + "normalized/"
_npDir = _directory + "numpy/"
synsysSubDir = "synsys/"
synsysFileName = "synsysData.csv" #1 time dim; 84 unique sensors; 25 activities
@staticmethod
def _fix_dir_str(dir):
return dir + '/' if dir[-1] != '/' else dir
@staticmethod
def get_raw(fileName, subDir = synsysSubDir):
subDir = dataset._fix_dir_str(subDir)
return dataset._rawDir + subDir + fileName
@staticmethod
def get_processed(fileName, subDir = synsysSubDir):
subDir = dataset._fix_dir_str(subDir)
return dataset._processedDir + subDir + fileName
@staticmethod
def get_normalized(fileName, subDir = synsysSubDir):
subDir = dataset._fix_dir_str(subDir)
return dataset._normDir + subDir + fileName
@staticmethod
def get_np(fileName, subDir = synsysSubDir):
subDir = dataset._fix_dir_str(subDir)
return dataset._npDir + subDir + fileName | class Dir:
misc = 'misc/'
datasets = 'datasets/'
keras_models = misc + 'kerasModels/'
autoencoders = kerasModels + 'autoencoder/'
@staticmethod
def get_autoencoder_dir_of_latent_size(latentSize):
return dir.autoencoders + 'ae' + str(latentSize) + '/'
class Dataset:
_directory = dir.datasets
_processed_dir = _directory + 'processed/'
_raw_dir = _directory + 'raw/'
_norm_dir = _directory + 'normalized/'
_np_dir = _directory + 'numpy/'
synsys_sub_dir = 'synsys/'
synsys_file_name = 'synsysData.csv'
@staticmethod
def _fix_dir_str(dir):
return dir + '/' if dir[-1] != '/' else dir
@staticmethod
def get_raw(fileName, subDir=synsysSubDir):
sub_dir = dataset._fix_dir_str(subDir)
return dataset._rawDir + subDir + fileName
@staticmethod
def get_processed(fileName, subDir=synsysSubDir):
sub_dir = dataset._fix_dir_str(subDir)
return dataset._processedDir + subDir + fileName
@staticmethod
def get_normalized(fileName, subDir=synsysSubDir):
sub_dir = dataset._fix_dir_str(subDir)
return dataset._normDir + subDir + fileName
@staticmethod
def get_np(fileName, subDir=synsysSubDir):
sub_dir = dataset._fix_dir_str(subDir)
return dataset._npDir + subDir + fileName |
print(8%10)
x = 'abc_%(key)s_'
x %= {'key':'value'}
print(x)
x = 'Sir %(Name)s '
x %= {'Name':'Lancelot'}
print(x)
| print(8 % 10)
x = 'abc_%(key)s_'
x %= {'key': 'value'}
print(x)
x = 'Sir %(Name)s '
x %= {'Name': 'Lancelot'}
print(x) |
class Solution:
def numJewelsInStones(self, jewels: str, stones: str) -> int:
hashmap = {}
for x in jewels:
hashmap[x] = 0
for x in stones:
if x in hashmap:
hashmap[x] += 1
return sum(hashmap.values())
class Solution(object):
def numJewelsInStones(self, jewels: str, stones: str) -> int:
jewels_set = set(jewels)
return sum(s in jewels_set for s in stones) # generator
| class Solution:
def num_jewels_in_stones(self, jewels: str, stones: str) -> int:
hashmap = {}
for x in jewels:
hashmap[x] = 0
for x in stones:
if x in hashmap:
hashmap[x] += 1
return sum(hashmap.values())
class Solution(object):
def num_jewels_in_stones(self, jewels: str, stones: str) -> int:
jewels_set = set(jewels)
return sum((s in jewels_set for s in stones)) |
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def sortedListToBST(self, head):
"""
:type head: ListNode
:rtype: TreeNode
"""
if head:
pre = None
slow = fast = head
while fast and fast.next:
pre = slow
slow = slow.next
fast = fast.next.next
root = TreeNode(slow.val)
if pre:
pre.next = None
root.left = self.sortedListToBST(head)
root.right = self.sortedListToBST(slow.next)
return root
| class Solution(object):
def sorted_list_to_bst(self, head):
"""
:type head: ListNode
:rtype: TreeNode
"""
if head:
pre = None
slow = fast = head
while fast and fast.next:
pre = slow
slow = slow.next
fast = fast.next.next
root = tree_node(slow.val)
if pre:
pre.next = None
root.left = self.sortedListToBST(head)
root.right = self.sortedListToBST(slow.next)
return root |
h, w, n = map(int, input().split())
li = list(map(int, input().split()))
curw = 0
for i in range(n):
if curw + li[i] <= w:
curw += li[i]
else:
print('NO')
exit(0)
if curw == w:
curw %= w
h -= 1
if not h:
print('YES')
exit(0)
print('NO') | (h, w, n) = map(int, input().split())
li = list(map(int, input().split()))
curw = 0
for i in range(n):
if curw + li[i] <= w:
curw += li[i]
else:
print('NO')
exit(0)
if curw == w:
curw %= w
h -= 1
if not h:
print('YES')
exit(0)
print('NO') |
"""Tests for the button component"""
def test_button_is_setup(generate_main):
"""
When the button is set in the yaml file if should be registered in main
"""
# Given
# When
main_cpp = generate_main("tests/component_tests/button/test_button.yaml")
# Then
assert "new wake_on_lan::WakeOnLanButton();" in main_cpp
assert "App.register_button" in main_cpp
assert "App.register_component" in main_cpp
def test_button_sets_mandatory_fields(generate_main):
"""
When the mandatory fields are set in the yaml, they should be set in main
"""
# Given
# When
main_cpp = generate_main("tests/component_tests/button/test_button.yaml")
# Then
assert 'wol_1->set_name("wol_test_1");' in main_cpp
assert "wol_2->set_macaddr(18, 52, 86, 120, 144, 171);" in main_cpp
def test_button_config_value_internal_set(generate_main):
"""
Test that the "internal" config value is correctly set
"""
# Given
# When
main_cpp = generate_main(
"tests/component_tests/button/test_button.yaml"
)
# Then
assert "wol_1->set_internal(true);" in main_cpp
assert "wol_2->set_internal(false);" in main_cpp
| """Tests for the button component"""
def test_button_is_setup(generate_main):
"""
When the button is set in the yaml file if should be registered in main
"""
main_cpp = generate_main('tests/component_tests/button/test_button.yaml')
assert 'new wake_on_lan::WakeOnLanButton();' in main_cpp
assert 'App.register_button' in main_cpp
assert 'App.register_component' in main_cpp
def test_button_sets_mandatory_fields(generate_main):
"""
When the mandatory fields are set in the yaml, they should be set in main
"""
main_cpp = generate_main('tests/component_tests/button/test_button.yaml')
assert 'wol_1->set_name("wol_test_1");' in main_cpp
assert 'wol_2->set_macaddr(18, 52, 86, 120, 144, 171);' in main_cpp
def test_button_config_value_internal_set(generate_main):
"""
Test that the "internal" config value is correctly set
"""
main_cpp = generate_main('tests/component_tests/button/test_button.yaml')
assert 'wol_1->set_internal(true);' in main_cpp
assert 'wol_2->set_internal(false);' in main_cpp |
tax_table = [(10000, 0.1), (20000, 0.2), (None, 0.3)]
def get_tax(init_salary, tax_table):
tax = 0
salary = init_salary
previous_limit = 0
for limit, ratio in tax_table:
if limit is None or init_salary < limit:
tax += salary * ratio
return tax
current_salary = limit - previous_limit
tax += current_salary * ratio
previous_limit = limit
salary -= current_salary
if __name__ == "__main__":
tax = get_tax(31000, tax_table)
print("tax: ", tax)
assert get_tax(500, tax_table) == 50
assert get_tax(10000, tax_table) == 1000
assert get_tax(10100, tax_table) == 1020
assert get_tax(20000, tax_table) == 3000
assert get_tax(20100, tax_table) == 3030
assert get_tax(30000, tax_table) == 6000
assert get_tax(36000, tax_table) == 7800
| tax_table = [(10000, 0.1), (20000, 0.2), (None, 0.3)]
def get_tax(init_salary, tax_table):
tax = 0
salary = init_salary
previous_limit = 0
for (limit, ratio) in tax_table:
if limit is None or init_salary < limit:
tax += salary * ratio
return tax
current_salary = limit - previous_limit
tax += current_salary * ratio
previous_limit = limit
salary -= current_salary
if __name__ == '__main__':
tax = get_tax(31000, tax_table)
print('tax: ', tax)
assert get_tax(500, tax_table) == 50
assert get_tax(10000, tax_table) == 1000
assert get_tax(10100, tax_table) == 1020
assert get_tax(20000, tax_table) == 3000
assert get_tax(20100, tax_table) == 3030
assert get_tax(30000, tax_table) == 6000
assert get_tax(36000, tax_table) == 7800 |
fhand = open(input("Enter file name: "))
schools = dict()
for ln in fhand:
if not ln.startswith('From '): continue
ln = ln.split()
mailer = ln[1]
pos = mailer.find('@')
school = mailer[pos+1:]
schools[school] = schools.get(school,0) + 1
print(schools)
| fhand = open(input('Enter file name: '))
schools = dict()
for ln in fhand:
if not ln.startswith('From '):
continue
ln = ln.split()
mailer = ln[1]
pos = mailer.find('@')
school = mailer[pos + 1:]
schools[school] = schools.get(school, 0) + 1
print(schools) |
""" Converting an postfix expression into output value"""
def check_precedence(op):
operators = ['(', ')', '^', '*', '/', '+', '-']
has_op = {'(': 0, ')': 0, '^': 3, '*': 2, '/': 2, '+': 1, '-': 1}
for i in range(len(operators)):
if op == operators[i]:
return has_op[operators[i]]
return -1
def operation(op1, op2, op_tn):
res = 0
a = int(op1)
b = int(op2)
if op_tn == '+':
res = a+b
elif op_tn == '-':
res = a-b
elif op_tn == '*':
res = a*b
elif op_tn == '/':
res = a/b
elif op_tn == '^':
res = pow(a, b)
return res
def find_post_val(str_input):
operators = ['(', ')', '^', '*', '/', '+', '-']
op_stack = []
curr_in = ""
# Iterate through the string from right to left, if you find an operator push it into the stack
for i in range(len(str_input)):
if str_input[i] == " ":
if curr_in in operators:
op_2 = op_stack.pop()
op_1 = op_stack.pop()
post_res = operation(op_1, op_2, curr_in)
op_stack.append(post_res)
else:
op_stack.append(curr_in)
curr_in = ""
else:
curr_in += str_input[i]
return op_stack.pop()
def main():
str_input = "10 2 * 3 5 * + 9 - "
print(find_post_val(str_input))
# Using the special variable
# __name__
if __name__ == "__main__":
main()
| """ Converting an postfix expression into output value"""
def check_precedence(op):
operators = ['(', ')', '^', '*', '/', '+', '-']
has_op = {'(': 0, ')': 0, '^': 3, '*': 2, '/': 2, '+': 1, '-': 1}
for i in range(len(operators)):
if op == operators[i]:
return has_op[operators[i]]
return -1
def operation(op1, op2, op_tn):
res = 0
a = int(op1)
b = int(op2)
if op_tn == '+':
res = a + b
elif op_tn == '-':
res = a - b
elif op_tn == '*':
res = a * b
elif op_tn == '/':
res = a / b
elif op_tn == '^':
res = pow(a, b)
return res
def find_post_val(str_input):
operators = ['(', ')', '^', '*', '/', '+', '-']
op_stack = []
curr_in = ''
for i in range(len(str_input)):
if str_input[i] == ' ':
if curr_in in operators:
op_2 = op_stack.pop()
op_1 = op_stack.pop()
post_res = operation(op_1, op_2, curr_in)
op_stack.append(post_res)
else:
op_stack.append(curr_in)
curr_in = ''
else:
curr_in += str_input[i]
return op_stack.pop()
def main():
str_input = '10 2 * 3 5 * + 9 - '
print(find_post_val(str_input))
if __name__ == '__main__':
main() |
def prod2sum(a, b, c, d):
firstPair = [abs(a*c + b*d), abs(b*c - a*d)]
firstPair.sort()
secondPair = [abs(a*c - b*d), abs(b*c + a*d)]
secondPair.sort()
delta = firstPair[0] - secondPair[0]
if delta < 0:
return [firstPair, secondPair]
elif delta > 0:
return [secondPair, firstPair]
else: # delta == 0
return [firstPair]
| def prod2sum(a, b, c, d):
first_pair = [abs(a * c + b * d), abs(b * c - a * d)]
firstPair.sort()
second_pair = [abs(a * c - b * d), abs(b * c + a * d)]
secondPair.sort()
delta = firstPair[0] - secondPair[0]
if delta < 0:
return [firstPair, secondPair]
elif delta > 0:
return [secondPair, firstPair]
else:
return [firstPair] |
# list example
list_test = ["item", 10, "item"]
print(list_test)
print(list_test[0])
# append item in list
list_test.append("testappend")
print(list_test)
# remove item list
list_test.remove("testappend") ## using value, not position
print(list)
# declaring tuples
# tuples are imutables lists
# dont possible concatenate tuples and lists
tuple2 = ("tuple", "tuple")
print(tuple2)
concat_tuple = ('one') + ('two')
print(concat_tuple)
# dictionary
# using dictionary for declaring lists with key and value
dictionary = {'one': 1, 'two': 2}
print(dictionary['one'])
print(dictionary.keys())
print(dictionary.values())
# using list for numbers
list_number = [1, 2, 3, 4]
print(max(list_number))
print(min(list_number))
print(len(list_number))
# count number of itens in list
list_cont = [0, 0, 1, 2, 35]
print(list_cont.count(0))
# using .index return num of index of element in list
# case not found generate error
print(list_cont.index(0))
# transform list in tuple or tuple in list
new_tuple = tuple(list_test)
print(new_tuple)
new_list = list(new_tuple)
print(new_list)
# using set for collection witch uniques elements
# A set is an unordered collection of elements
# set has no index
list_set = {"ade", "ade"} # use { for init set
list_set.add("teste")
print(list_set)
| list_test = ['item', 10, 'item']
print(list_test)
print(list_test[0])
list_test.append('testappend')
print(list_test)
list_test.remove('testappend')
print(list)
tuple2 = ('tuple', 'tuple')
print(tuple2)
concat_tuple = 'one' + 'two'
print(concat_tuple)
dictionary = {'one': 1, 'two': 2}
print(dictionary['one'])
print(dictionary.keys())
print(dictionary.values())
list_number = [1, 2, 3, 4]
print(max(list_number))
print(min(list_number))
print(len(list_number))
list_cont = [0, 0, 1, 2, 35]
print(list_cont.count(0))
print(list_cont.index(0))
new_tuple = tuple(list_test)
print(new_tuple)
new_list = list(new_tuple)
print(new_list)
list_set = {'ade', 'ade'}
list_set.add('teste')
print(list_set) |
class MaterialGameSettings:
alpha_blend = None
face_orientation = None
invisible = None
physics = None
text = None
use_backface_culling = None
| class Materialgamesettings:
alpha_blend = None
face_orientation = None
invisible = None
physics = None
text = None
use_backface_culling = None |
class Dinglemouse(object):
def __init__(self, queues, capacity):
self.queues = list(map(list, queues))
self.cap = capacity
self.passengers = []
def theLift(self):
queues = self.queues
cap = self.cap
floors = len(queues)
floors_visited = [0]
def empty(seq):
try:
return all(map(empty, seq))
except TypeError:
return False
def move(start=floors_visited[-1], direction='up'):
if empty(queues):
return
if direction == 'up':
floors_to_visit = [x for x in range(start, floors)]
else:
floors_to_visit = [x for x in range(start, -1, -1)]
for floor in floors_to_visit:
stop = False
remove = []
if floor in self.passengers:
stop = True
self.passengers = [x for x in self.passengers if x != floor]
for waiter in queues[floor]:
if direction == 'up':
if (waiter > floor):
stop = True
if len(self.passengers) < cap:
self.passengers.append(waiter)
remove.append(waiter)
else:
if (waiter < floor):
stop = True
if len(self.passengers) < cap:
self.passengers.append(waiter)
remove.append(waiter)
for waiter in remove:
queues[floor].remove(waiter)
if stop and (floors_visited[-1] != floor):
floors_visited.append(floor)
if not empty(self.passengers):
continue
elif empty(queues):
if floors_visited[-1] != 0:
floors_visited.append(0)
break
elif (direction == 'up') and empty(queues[floor+1:]):
move(start=floor, direction='down')
elif (direction == 'down') and empty(queues[:floor]):
move(start=floor, direction='up')
return
move()
return floors_visited
if __name__ == '__main__':
lift = Dinglemouse(((), (), (5, 5, 5), (), (), (), ()), 5)
print(lift.theLift())
lift = Dinglemouse(((), (), (1, 1), (), (), (), ()), 5)
print(lift.theLift())
lift = Dinglemouse(((), (3,), (4,), (), (5,), (), ()), 5)
print(lift.theLift())
lift = Dinglemouse(((), (0,), (), (), (2,), (3,), ()), 5)
print(lift.theLift())
lift = Dinglemouse(((3,), (2,), (0,), (2,), (), (), (5,)), 5)
print(lift.theLift())
lift = Dinglemouse(((), (), (4, 4, 4, 4), (), (2, 2, 2, 2), (), ()), 2)
print(lift.theLift())
lift = Dinglemouse(((3, 3, 3, 3, 3, 3), (), (), (), (), (), ()), 5)
print(lift.theLift())
lift = Dinglemouse((
(6, 11, 2, 2), (14, 12, 8, 10, 0), (12, 11, 5, 8), (6, 13, 2), (),
(10, 3, 3, 1), (), (12, 12, 12), (14, 6), (13, 7, 1), (2, 7),
(3, 1), (), (3, 11, 1, 3), (11, 3, 4, 0, 8)), 4)
print(lift.theLift())
| class Dinglemouse(object):
def __init__(self, queues, capacity):
self.queues = list(map(list, queues))
self.cap = capacity
self.passengers = []
def the_lift(self):
queues = self.queues
cap = self.cap
floors = len(queues)
floors_visited = [0]
def empty(seq):
try:
return all(map(empty, seq))
except TypeError:
return False
def move(start=floors_visited[-1], direction='up'):
if empty(queues):
return
if direction == 'up':
floors_to_visit = [x for x in range(start, floors)]
else:
floors_to_visit = [x for x in range(start, -1, -1)]
for floor in floors_to_visit:
stop = False
remove = []
if floor in self.passengers:
stop = True
self.passengers = [x for x in self.passengers if x != floor]
for waiter in queues[floor]:
if direction == 'up':
if waiter > floor:
stop = True
if len(self.passengers) < cap:
self.passengers.append(waiter)
remove.append(waiter)
elif waiter < floor:
stop = True
if len(self.passengers) < cap:
self.passengers.append(waiter)
remove.append(waiter)
for waiter in remove:
queues[floor].remove(waiter)
if stop and floors_visited[-1] != floor:
floors_visited.append(floor)
if not empty(self.passengers):
continue
elif empty(queues):
if floors_visited[-1] != 0:
floors_visited.append(0)
break
elif direction == 'up' and empty(queues[floor + 1:]):
move(start=floor, direction='down')
elif direction == 'down' and empty(queues[:floor]):
move(start=floor, direction='up')
return
move()
return floors_visited
if __name__ == '__main__':
lift = dinglemouse(((), (), (5, 5, 5), (), (), (), ()), 5)
print(lift.theLift())
lift = dinglemouse(((), (), (1, 1), (), (), (), ()), 5)
print(lift.theLift())
lift = dinglemouse(((), (3,), (4,), (), (5,), (), ()), 5)
print(lift.theLift())
lift = dinglemouse(((), (0,), (), (), (2,), (3,), ()), 5)
print(lift.theLift())
lift = dinglemouse(((3,), (2,), (0,), (2,), (), (), (5,)), 5)
print(lift.theLift())
lift = dinglemouse(((), (), (4, 4, 4, 4), (), (2, 2, 2, 2), (), ()), 2)
print(lift.theLift())
lift = dinglemouse(((3, 3, 3, 3, 3, 3), (), (), (), (), (), ()), 5)
print(lift.theLift())
lift = dinglemouse(((6, 11, 2, 2), (14, 12, 8, 10, 0), (12, 11, 5, 8), (6, 13, 2), (), (10, 3, 3, 1), (), (12, 12, 12), (14, 6), (13, 7, 1), (2, 7), (3, 1), (), (3, 11, 1, 3), (11, 3, 4, 0, 8)), 4)
print(lift.theLift()) |
class DotNotationDict(dict):
'''
Dictionary subclass that allows attribute
access using dot notation, eg:
>>> dnd = DotNotationDict({'test': True})
>>> dnd.test
True
'''
def __getattr__(self, key):
try:
return self[key]
except KeyError:
raise AttributeError("DotNotationDict has no attribute '%s'" % key)
def __setattr__(self, key, value):
self[key] = value
| class Dotnotationdict(dict):
"""
Dictionary subclass that allows attribute
access using dot notation, eg:
>>> dnd = DotNotationDict({'test': True})
>>> dnd.test
True
"""
def __getattr__(self, key):
try:
return self[key]
except KeyError:
raise attribute_error("DotNotationDict has no attribute '%s'" % key)
def __setattr__(self, key, value):
self[key] = value |
class Solution(object):
def containsDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
## storing unique elements in a list
unique = []
for i in nums:
## if element not in the list, add it to the list
if i not in unique:
unique.append(i)
## otherwise, return True (i.e. the given list contains duplicates)
else:
return True
return False | class Solution(object):
def contains_duplicate(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
unique = []
for i in nums:
if i not in unique:
unique.append(i)
else:
return True
return False |
'''
Condition group where conditions are set
'''
class ConditionGroup():
def __init__(self):
self.conditions = []
self.success = 'success'
self.failed = 'failed'
def add_condition(self, l1, optn, arg, then, else_value):
input_json = {'l1': l1, 'optn': optn, 'arg': arg, 'then': then, 'else_value': else_value}
self.conditions.append(input_json)
@property
def conditions(self):
return self.conditions
def response(self, success, failed):
self.success = success
self.failed = failed
| """
Condition group where conditions are set
"""
class Conditiongroup:
def __init__(self):
self.conditions = []
self.success = 'success'
self.failed = 'failed'
def add_condition(self, l1, optn, arg, then, else_value):
input_json = {'l1': l1, 'optn': optn, 'arg': arg, 'then': then, 'else_value': else_value}
self.conditions.append(input_json)
@property
def conditions(self):
return self.conditions
def response(self, success, failed):
self.success = success
self.failed = failed |
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# FILE: stop_words.py
#
# Simple routine that removes stop words from a string
#
# Copyright by Author. All rights reserved. Not for reuse without
# express permissions.
#
def remove_stops(text=None):
new_text = ""
nt2 = []
text_list = text.split("\n")
for line in text_list:
word_list = line.split(' ')
l2 = []
for w in word_list:
wlower = w.lower()
if( not wlower in STOPLIST ):
#print "keeping:",w
l2.append(w)
#else:
# print "removing:",w
if( l2 ):
new_line = u" ".join(l2)
nt2.append(new_line)
if( len(nt2)==0 ):
new_text = ""
elif( len(nt2)==1 ):
new_text = nt2[0]
else:
new_text = u"\n".join(nt2)
return new_text
STOPLIST = {
'n':1,
'necessary':1,
'need':1,
'needed':1,
'needing':1,
'newest':1,
'next':1,
'no':1,
'nobody':1,
'non':1,
'noone':1,
'not':1,
'nothing':1,
'now':1,
'nowhere':1,
'of':1,
'off':1,
'often':1,
'new':1,
'old':1,
'older':1,
'oldest':1,
'on':1,
'once':1,
'one':1,
'only':1,
'open':1,
'again':1,
'among':1,
'already':1,
'about':1,
'above':1,
'against':1,
'alone':1,
'after':1,
'also':1,
'although':1,
'along':1,
'always':1,
'an':1,
'across':1,
'b':1,
'and':1,
'another':1,
'ask':1,
'c':1,
'asking':1,
'asks':1,
'backed':1,
'away':1,
'a':1,
'should':1,
'show':1,
'came':1,
'all':1,
'almost':1,
'before':1,
'began':1,
'back':1,
'backing':1,
'be':1,
'became':1,
'because':1,
'becomes':1,
'been':1,
'at':1,
'behind':1,
'being':1,
'best':1,
'better':1,
'between':1,
'big':1,
'showed':1,
'ended':1,
'ending':1,
'both':1,
'but':1,
'by':1,
'asked':1,
'backs':1,
'can':1,
'cannot':1,
'number':1,
'numbers':1,
'o':1,
'case':1,
'few':1,
'find':1,
'finds':1,
'cases':1,
'clearly':1,
'her':1,
'herself':1,
'come':1,
'could':1,
'd':1,
'did':1,
'here':1,
'beings':1,
'fact':1,
'far':1,
'felt':1,
'become':1,
'first':1,
'for':1,
'four':1,
'from':1,
'full':1,
'fully':1,
'furthers':1,
'gave':1,
'general':1,
'generally':1,
'get':1,
'gets':1,
'gives':1,
'facts':1,
'go':1,
'going':1,
'good':1,
'goods':1,
'certain':1,
'certainly':1,
'clear':1,
'great':1,
'greater':1,
'greatest':1,
'group':1,
'grouped':1,
'grouping':1,
'groups':1,
'h':1,
'got':1,
'has':1,
'g':1,
'have':1,
'having':1,
'he':1,
'further':1,
'furthered':1,
'had':1,
'furthering':1,
'itself':1,
'faces':1,
'highest':1,
'him':1,
'himself':1,
'his':1,
'how':1,
'however':1,
'i':1,
'if':1,
'important':1,
'interests':1,
'into':1,
'is':1,
'it':1,
'its':1,
'j':1,
'anyone':1,
'anything':1,
'anywhere':1,
'are':1,
'area':1,
'areas':1,
'around':1,
'as':1,
'seconds':1,
'see':1,
'seem':1,
'seemed':1,
'seeming':1,
'seems':1,
'sees':1,
'right':1,
'several':1,
'shall':1,
'she':1,
'enough':1,
'even':1,
'evenly':1,
'over':1,
'p':1,
'part':1,
'parted':1,
'parting':1,
'parts':1,
'per':1,
'down':1,
'place':1,
'places':1,
'point':1,
'pointed':1,
'pointing':1,
'points':1,
'possible':1,
'present':1,
'presented':1,
'presenting':1,
'ends':1,
'high':1,
'mrs':1,
'much':1,
'must':1,
'my':1,
'myself':1,
'presents':1,
'down':1,
'problem':1,
'problems':1,
'put':1,
'puts':1,
'q':1,
'quite':1,
'will':1,
'with':1,
'within':1,
'r':1,
're':1,
'rather':1,
'really':1,
'room':1,
'rooms':1,
's':1,
'said':1,
'same':1,
'right':1,
'showing':1,
'shows':1,
'side':1,
'sides':1,
'since':1,
'small':1,
'smaller':1,
'smallest':1,
'so':1,
'some':1,
'somebody':1,
'someone':1,
'something':1,
'somewhere':1,
'state':1,
'states':1,
'such':1,
'sure':1,
't':1,
'take':1,
'taken':1,
'than':1,
'that':1,
'the':1,
'their':1,
'then':1,
'there':1,
'therefore':1,
'these':1,
'x':1,
'thought':1,
'thoughts':1,
'three':1,
'through':1,
'thus':1,
'to':1,
'today':1,
'together':1,
'too':1,
'took':1,
'toward':1,
'turn':1,
'turned':1,
'turning':1,
'turns':1,
'two':1,
'still':1,
'u':1,
'under':1,
'until':1,
'up':1,
'others':1,
'upon':1,
'us':1,
'use':1,
'used':1,
'uses':1,
'v':1,
'very':1,
'w':1,
'want':1,
'wanted':1,
'wanting':1,
'wants':1,
'was':1,
'way':1,
'we':1,
'well':1,
'wells':1,
'went':1,
'were':1,
'what':1,
'when':1,
'where':1,
'whether':1,
'which':1,
'while':1,
'who':1,
'whole':1,
'y':1,
'year':1,
'years':1,
'yet':1,
'you':1,
'everyone':1,
'everything':1,
'everywhere':1,
'young':1,
'younger':1,
'youngest':1,
'your':1,
'yours':1,
'z':1,
'ever':1,
'works':1,
'every':1,
'everybody':1,
'f':1,
'face':1,
'other':1,
'our':1,
'out':1,
'just':1,
'interesting':1,
'high':1,
'might':1,
'k':1,
'keep':1,
'keeps':1,
'give':1,
'given':1,
'higher':1,
'kind':1,
'knew':1,
'know':1,
'known':1,
'knows':1,
'l':1,
'large':1,
'largely':1,
'last':1,
'later':1,
'latest':1,
'least':1,
'less':1,
'needs':1,
'never':1,
'newer':1,
'let':1,
'lets':1,
'like':1,
'likely':1,
'long':1,
'high':1,
'longer':1,
'longest':1,
'm':1,
'made':1,
'make':1,
'making':1,
'man':1,
'many':1,
'may':1,
'me':1,
'member':1,
'members':1,
'men':1,
'more':1,
'in':1,
'interest':1,
'interested':1,
'most':1,
'mostly':1,
'mr':1,
'opened':1,
'opening':1,
'new':1,
'opens':1,
'or':1,
'perhaps':1,
'order':1,
'ordered':1,
'ordering':1,
'orders':1,
'differ':1,
'different':1,
'differently':1,
'do':1,
'does':1,
'done':1,
'downed':1,
'downing':1,
'downs':1,
'they':1,
'thing':1,
'things':1,
'think':1,
'thinks':1,
'this':1,
'those':1,
'ways':1,
'why':1,
'without':1,
'work':1,
'worked':1,
'working':1,
'would':1,
'during':1,
'e':1,
'each':1,
'early':1,
'either':1,
'end':1,
'though':1,
'still':1,
'whose':1,
'saw':1,
'say':1,
'says':1,
'them':1,
'second':1,
'any':1,
'anybody':1,
'@':1,
'...':1,
';':1,
':':1,
'&':1,
'!':1,
'-':1,
'.':1,
'rt':1,
'via':1,
'0':1,
'1':1,
'2':1,
'3':1,
'4':1,
'5':1,
'6':1,
'7':1,
'8':1,
'9':1
} | def remove_stops(text=None):
new_text = ''
nt2 = []
text_list = text.split('\n')
for line in text_list:
word_list = line.split(' ')
l2 = []
for w in word_list:
wlower = w.lower()
if not wlower in STOPLIST:
l2.append(w)
if l2:
new_line = u' '.join(l2)
nt2.append(new_line)
if len(nt2) == 0:
new_text = ''
elif len(nt2) == 1:
new_text = nt2[0]
else:
new_text = u'\n'.join(nt2)
return new_text
stoplist = {'n': 1, 'necessary': 1, 'need': 1, 'needed': 1, 'needing': 1, 'newest': 1, 'next': 1, 'no': 1, 'nobody': 1, 'non': 1, 'noone': 1, 'not': 1, 'nothing': 1, 'now': 1, 'nowhere': 1, 'of': 1, 'off': 1, 'often': 1, 'new': 1, 'old': 1, 'older': 1, 'oldest': 1, 'on': 1, 'once': 1, 'one': 1, 'only': 1, 'open': 1, 'again': 1, 'among': 1, 'already': 1, 'about': 1, 'above': 1, 'against': 1, 'alone': 1, 'after': 1, 'also': 1, 'although': 1, 'along': 1, 'always': 1, 'an': 1, 'across': 1, 'b': 1, 'and': 1, 'another': 1, 'ask': 1, 'c': 1, 'asking': 1, 'asks': 1, 'backed': 1, 'away': 1, 'a': 1, 'should': 1, 'show': 1, 'came': 1, 'all': 1, 'almost': 1, 'before': 1, 'began': 1, 'back': 1, 'backing': 1, 'be': 1, 'became': 1, 'because': 1, 'becomes': 1, 'been': 1, 'at': 1, 'behind': 1, 'being': 1, 'best': 1, 'better': 1, 'between': 1, 'big': 1, 'showed': 1, 'ended': 1, 'ending': 1, 'both': 1, 'but': 1, 'by': 1, 'asked': 1, 'backs': 1, 'can': 1, 'cannot': 1, 'number': 1, 'numbers': 1, 'o': 1, 'case': 1, 'few': 1, 'find': 1, 'finds': 1, 'cases': 1, 'clearly': 1, 'her': 1, 'herself': 1, 'come': 1, 'could': 1, 'd': 1, 'did': 1, 'here': 1, 'beings': 1, 'fact': 1, 'far': 1, 'felt': 1, 'become': 1, 'first': 1, 'for': 1, 'four': 1, 'from': 1, 'full': 1, 'fully': 1, 'furthers': 1, 'gave': 1, 'general': 1, 'generally': 1, 'get': 1, 'gets': 1, 'gives': 1, 'facts': 1, 'go': 1, 'going': 1, 'good': 1, 'goods': 1, 'certain': 1, 'certainly': 1, 'clear': 1, 'great': 1, 'greater': 1, 'greatest': 1, 'group': 1, 'grouped': 1, 'grouping': 1, 'groups': 1, 'h': 1, 'got': 1, 'has': 1, 'g': 1, 'have': 1, 'having': 1, 'he': 1, 'further': 1, 'furthered': 1, 'had': 1, 'furthering': 1, 'itself': 1, 'faces': 1, 'highest': 1, 'him': 1, 'himself': 1, 'his': 1, 'how': 1, 'however': 1, 'i': 1, 'if': 1, 'important': 1, 'interests': 1, 'into': 1, 'is': 1, 'it': 1, 'its': 1, 'j': 1, 'anyone': 1, 'anything': 1, 'anywhere': 1, 'are': 1, 'area': 1, 'areas': 1, 'around': 1, 'as': 1, 'seconds': 1, 'see': 1, 'seem': 1, 'seemed': 1, 'seeming': 1, 'seems': 1, 'sees': 1, 'right': 1, 'several': 1, 'shall': 1, 'she': 1, 'enough': 1, 'even': 1, 'evenly': 1, 'over': 1, 'p': 1, 'part': 1, 'parted': 1, 'parting': 1, 'parts': 1, 'per': 1, 'down': 1, 'place': 1, 'places': 1, 'point': 1, 'pointed': 1, 'pointing': 1, 'points': 1, 'possible': 1, 'present': 1, 'presented': 1, 'presenting': 1, 'ends': 1, 'high': 1, 'mrs': 1, 'much': 1, 'must': 1, 'my': 1, 'myself': 1, 'presents': 1, 'down': 1, 'problem': 1, 'problems': 1, 'put': 1, 'puts': 1, 'q': 1, 'quite': 1, 'will': 1, 'with': 1, 'within': 1, 'r': 1, 're': 1, 'rather': 1, 'really': 1, 'room': 1, 'rooms': 1, 's': 1, 'said': 1, 'same': 1, 'right': 1, 'showing': 1, 'shows': 1, 'side': 1, 'sides': 1, 'since': 1, 'small': 1, 'smaller': 1, 'smallest': 1, 'so': 1, 'some': 1, 'somebody': 1, 'someone': 1, 'something': 1, 'somewhere': 1, 'state': 1, 'states': 1, 'such': 1, 'sure': 1, 't': 1, 'take': 1, 'taken': 1, 'than': 1, 'that': 1, 'the': 1, 'their': 1, 'then': 1, 'there': 1, 'therefore': 1, 'these': 1, 'x': 1, 'thought': 1, 'thoughts': 1, 'three': 1, 'through': 1, 'thus': 1, 'to': 1, 'today': 1, 'together': 1, 'too': 1, 'took': 1, 'toward': 1, 'turn': 1, 'turned': 1, 'turning': 1, 'turns': 1, 'two': 1, 'still': 1, 'u': 1, 'under': 1, 'until': 1, 'up': 1, 'others': 1, 'upon': 1, 'us': 1, 'use': 1, 'used': 1, 'uses': 1, 'v': 1, 'very': 1, 'w': 1, 'want': 1, 'wanted': 1, 'wanting': 1, 'wants': 1, 'was': 1, 'way': 1, 'we': 1, 'well': 1, 'wells': 1, 'went': 1, 'were': 1, 'what': 1, 'when': 1, 'where': 1, 'whether': 1, 'which': 1, 'while': 1, 'who': 1, 'whole': 1, 'y': 1, 'year': 1, 'years': 1, 'yet': 1, 'you': 1, 'everyone': 1, 'everything': 1, 'everywhere': 1, 'young': 1, 'younger': 1, 'youngest': 1, 'your': 1, 'yours': 1, 'z': 1, 'ever': 1, 'works': 1, 'every': 1, 'everybody': 1, 'f': 1, 'face': 1, 'other': 1, 'our': 1, 'out': 1, 'just': 1, 'interesting': 1, 'high': 1, 'might': 1, 'k': 1, 'keep': 1, 'keeps': 1, 'give': 1, 'given': 1, 'higher': 1, 'kind': 1, 'knew': 1, 'know': 1, 'known': 1, 'knows': 1, 'l': 1, 'large': 1, 'largely': 1, 'last': 1, 'later': 1, 'latest': 1, 'least': 1, 'less': 1, 'needs': 1, 'never': 1, 'newer': 1, 'let': 1, 'lets': 1, 'like': 1, 'likely': 1, 'long': 1, 'high': 1, 'longer': 1, 'longest': 1, 'm': 1, 'made': 1, 'make': 1, 'making': 1, 'man': 1, 'many': 1, 'may': 1, 'me': 1, 'member': 1, 'members': 1, 'men': 1, 'more': 1, 'in': 1, 'interest': 1, 'interested': 1, 'most': 1, 'mostly': 1, 'mr': 1, 'opened': 1, 'opening': 1, 'new': 1, 'opens': 1, 'or': 1, 'perhaps': 1, 'order': 1, 'ordered': 1, 'ordering': 1, 'orders': 1, 'differ': 1, 'different': 1, 'differently': 1, 'do': 1, 'does': 1, 'done': 1, 'downed': 1, 'downing': 1, 'downs': 1, 'they': 1, 'thing': 1, 'things': 1, 'think': 1, 'thinks': 1, 'this': 1, 'those': 1, 'ways': 1, 'why': 1, 'without': 1, 'work': 1, 'worked': 1, 'working': 1, 'would': 1, 'during': 1, 'e': 1, 'each': 1, 'early': 1, 'either': 1, 'end': 1, 'though': 1, 'still': 1, 'whose': 1, 'saw': 1, 'say': 1, 'says': 1, 'them': 1, 'second': 1, 'any': 1, 'anybody': 1, '@': 1, '...': 1, ';': 1, ':': 1, '&': 1, '!': 1, '-': 1, '.': 1, 'rt': 1, 'via': 1, '0': 1, '1': 1, '2': 1, '3': 1, '4': 1, '5': 1, '6': 1, '7': 1, '8': 1, '9': 1} |
class Error(Exception):
def __init__(self, s, context=None, exception=None):
Exception.__init__(self, s)
self.context = context
self.exception = exception
| class Error(Exception):
def __init__(self, s, context=None, exception=None):
Exception.__init__(self, s)
self.context = context
self.exception = exception |
print("Enter 'quit' when done\n")
while True:
# ask for card number
credit_num = input("Number: ")
# allow user to end program
if credit_num.casefold() == "quit":
break
# if input given isn't numeric re-ask for number
while not credit_num.isdigit():
print("\nEnter numbers only please\n")
credit_num = input("Number: ")
if credit_num == "quit":
break
if credit_num == "quit":
break
# reset values to 0
number_count = 0
validity = 0
# Luhn's Algorithm for verifying if card number is valid
for number in credit_num[-2::-2]:
for digit in str(int(number) * 2):
number_count += int(digit)
for number in credit_num[-1::-2]:
number_count += int(number)
# check if number is easily divisible by 10 (Luhn's Algorithm)
if number_count % 10 == 0:
validity += 1
# identify type of card and if number length validates card type
if int(credit_num[0:2]) in [34, 37] and len(credit_num) == 15:
card_type = "American Express"
validity += 1
elif int(credit_num[0:2]) in [51, 52, 53, 54, 55] and len(credit_num) == 16:
card_type = "MasterCard"
validity += 1
elif int(credit_num[0]) == 4 and len(credit_num) in [13, 16]:
card_type = "Visa"
validity += 1
# print either the card type or invalid
if validity == 2:
print(card_type + "\n")
else:
print("Invalid\n")
| print("Enter 'quit' when done\n")
while True:
credit_num = input('Number: ')
if credit_num.casefold() == 'quit':
break
while not credit_num.isdigit():
print('\nEnter numbers only please\n')
credit_num = input('Number: ')
if credit_num == 'quit':
break
if credit_num == 'quit':
break
number_count = 0
validity = 0
for number in credit_num[-2::-2]:
for digit in str(int(number) * 2):
number_count += int(digit)
for number in credit_num[-1::-2]:
number_count += int(number)
if number_count % 10 == 0:
validity += 1
if int(credit_num[0:2]) in [34, 37] and len(credit_num) == 15:
card_type = 'American Express'
validity += 1
elif int(credit_num[0:2]) in [51, 52, 53, 54, 55] and len(credit_num) == 16:
card_type = 'MasterCard'
validity += 1
elif int(credit_num[0]) == 4 and len(credit_num) in [13, 16]:
card_type = 'Visa'
validity += 1
if validity == 2:
print(card_type + '\n')
else:
print('Invalid\n') |
class Solution:
def winnerOfGame(self, colors: str) -> bool:
# print(colors[:-1])
count1, count2 = 0, 0
for i in range(1, len(colors)-1):
if colors[i-1] == colors[i] == colors[i+1] == "A":
count1 += 1
elif colors[i-1] == colors[i] == colors[i+1] == "B":
count2 += 1
return count1 > count2
| class Solution:
def winner_of_game(self, colors: str) -> bool:
(count1, count2) = (0, 0)
for i in range(1, len(colors) - 1):
if colors[i - 1] == colors[i] == colors[i + 1] == 'A':
count1 += 1
elif colors[i - 1] == colors[i] == colors[i + 1] == 'B':
count2 += 1
return count1 > count2 |
#!/usr/bin/env python3
#!/usr/bin/python
print(" this".strip())
| print(' this'.strip()) |
# Super Plumber #
# November 26, 2020
# By Robin Nash
# November 26 2020 #
y,x = r,c = 6,5
data = []
##for i in range(y):
## data.append(input())
##data = ['..3.......', '..........', '..7.**....', '.9**...1..', '..8..9....']
grid = [\
'.**.1',\
'.*9..',\
'.5...',\
'.....',\
'.....',\
'.....',]
x,y = c,r = 4,4
grid = [\
'...1',\
'..9.',\
'.5..',\
'....']
grid = ['*'*(x+2)]+['*'+row+'*' for row in grid]+['*'*(x+2)]
def buildWallDown(grid,r=1,c=1):
if r == len(grid)-1:
return grid
if c == len(grid[0])-1:
return buildWallDown(grid,r+1,1)
if grid[r][c-1] == grid[r][c+1] == grid[r-1][c] == '*':
grid[r] = grid[r][:c]+'*'+grid[r][c+1:]
return buildWallDown(grid,r,c+1)
def buildWallUp(grid,r=r,c=1):
if r == 0 and c == len(grid[0])-1:
return grid
if c == len(grid[0])-1:
return buildWallUp(grid,r-1,1)
if grid[r][c-1] == grid[r][c+1] == grid[r+1][c] == '*':
grid[r] = grid[r][:c]+'*'+grid[r][c+1:]
return buildWallUp(grid,r,c+1)
def buildWallUp(grid,y=r-1,x=1):
if x == len(grid[0])-1:
return grid
if x == len(grid[0])-2 and y==len(grid)-2: #Skip last cell
y -= 1
if y == 0:
return buildWallUp(grid, r, x+1)
if grid[y][x-1] == grid[y][x+1] == grid[y+1][x] == '*':
grid[y] = grid[y][:x]+'*'+grid[y][x+1:]
return buildWallUp(grid,y-1,x)
def buildWalls(grid,y=r-1,x=1,up = True):
if x == len(grid[0])-1:
return grid if not up else buildWalls(grid,y=1,x=1,up=False)
if x == len(grid[0])-2 and y==len(grid)-2 and up: #Skip last cell up
y -= 1
if y == 0 or y == r+2:
return buildWalls(grid, r if up else 1, x+1,up)
if grid[y][x-1] == grid[y][x+1] == grid[y-1 + 2*int(up)][x] == '*':
grid[y] = grid[y][:x]+'*'+grid[y][x+1:]
return buildWalls(grid,y+1 -2*int(up),x,up)
dp = [[0 for i in grid[0]] for y in grid]
def dynamic(dp,x=1):
if x == len(grid)-1:
return dp
up = [0 for i in range(len(dp))]
down = up[:]
for y in range(1,len(grid)-1):
if grid[y][x] == '*':
continue
down[y] = dp[y][x-1]+down[y-1]+int(grid[y][x]) if grid[y][x].isdigit() else 0
for y in range(len(grid)-2,0,-1):
if grid[y][x] =='*':
continue
up[y] = dp[y][x-1]+up[y+1]+ int(grid[y][x]) if grid[y][x].isdigit() else 0
for y in range(1,len(grid)-1):
dp[y][x] = max(up[y],down[y])
## print(up)
print(down)
return dynamic(dp,x+1)
##grid = buildWallDown(grid)
grid = buildWalls(grid)
dp = dynamic(dp)
for y in range(len(grid)):
## print("".join(row))
print("".join(map(str,dp[y])))
##int('*') if '*'.isdigit() else 0
#1606431716.206388 | (y, x) = (r, c) = (6, 5)
data = []
grid = ['.**.1', '.*9..', '.5...', '.....', '.....', '.....']
(x, y) = (c, r) = (4, 4)
grid = ['...1', '..9.', '.5..', '....']
grid = ['*' * (x + 2)] + ['*' + row + '*' for row in grid] + ['*' * (x + 2)]
def build_wall_down(grid, r=1, c=1):
if r == len(grid) - 1:
return grid
if c == len(grid[0]) - 1:
return build_wall_down(grid, r + 1, 1)
if grid[r][c - 1] == grid[r][c + 1] == grid[r - 1][c] == '*':
grid[r] = grid[r][:c] + '*' + grid[r][c + 1:]
return build_wall_down(grid, r, c + 1)
def build_wall_up(grid, r=r, c=1):
if r == 0 and c == len(grid[0]) - 1:
return grid
if c == len(grid[0]) - 1:
return build_wall_up(grid, r - 1, 1)
if grid[r][c - 1] == grid[r][c + 1] == grid[r + 1][c] == '*':
grid[r] = grid[r][:c] + '*' + grid[r][c + 1:]
return build_wall_up(grid, r, c + 1)
def build_wall_up(grid, y=r - 1, x=1):
if x == len(grid[0]) - 1:
return grid
if x == len(grid[0]) - 2 and y == len(grid) - 2:
y -= 1
if y == 0:
return build_wall_up(grid, r, x + 1)
if grid[y][x - 1] == grid[y][x + 1] == grid[y + 1][x] == '*':
grid[y] = grid[y][:x] + '*' + grid[y][x + 1:]
return build_wall_up(grid, y - 1, x)
def build_walls(grid, y=r - 1, x=1, up=True):
if x == len(grid[0]) - 1:
return grid if not up else build_walls(grid, y=1, x=1, up=False)
if x == len(grid[0]) - 2 and y == len(grid) - 2 and up:
y -= 1
if y == 0 or y == r + 2:
return build_walls(grid, r if up else 1, x + 1, up)
if grid[y][x - 1] == grid[y][x + 1] == grid[y - 1 + 2 * int(up)][x] == '*':
grid[y] = grid[y][:x] + '*' + grid[y][x + 1:]
return build_walls(grid, y + 1 - 2 * int(up), x, up)
dp = [[0 for i in grid[0]] for y in grid]
def dynamic(dp, x=1):
if x == len(grid) - 1:
return dp
up = [0 for i in range(len(dp))]
down = up[:]
for y in range(1, len(grid) - 1):
if grid[y][x] == '*':
continue
down[y] = dp[y][x - 1] + down[y - 1] + int(grid[y][x]) if grid[y][x].isdigit() else 0
for y in range(len(grid) - 2, 0, -1):
if grid[y][x] == '*':
continue
up[y] = dp[y][x - 1] + up[y + 1] + int(grid[y][x]) if grid[y][x].isdigit() else 0
for y in range(1, len(grid) - 1):
dp[y][x] = max(up[y], down[y])
print(down)
return dynamic(dp, x + 1)
grid = build_walls(grid)
dp = dynamic(dp)
for y in range(len(grid)):
print(''.join(map(str, dp[y]))) |
# Copyright (c) 2013 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
'includes': [
'../../../../build/common.gypi',
],
'conditions': [
['target_arch=="ia32" or target_arch=="x64"', {
'targets': [
{
'target_name': 'ncval_new',
'type': 'executable',
'sources': ['ncval.cc', 'elf_load.cc'],
'dependencies': [
'<(DEPTH)/native_client/src/shared/platform/platform.gyp:platform',
'<(DEPTH)/native_client/src/trusted/validator_arm/validator_arm.gyp:arm_validator_core',
'<(DEPTH)/native_client/src/trusted/validator_arm/validator_arm.gyp:arm_validator_reporters',
'<(DEPTH)/native_client/src/trusted/validator_ragel/rdfa_validator.gyp:rdfa_validator',
],
},
]
}],
],
}
| {'includes': ['../../../../build/common.gypi'], 'conditions': [['target_arch=="ia32" or target_arch=="x64"', {'targets': [{'target_name': 'ncval_new', 'type': 'executable', 'sources': ['ncval.cc', 'elf_load.cc'], 'dependencies': ['<(DEPTH)/native_client/src/shared/platform/platform.gyp:platform', '<(DEPTH)/native_client/src/trusted/validator_arm/validator_arm.gyp:arm_validator_core', '<(DEPTH)/native_client/src/trusted/validator_arm/validator_arm.gyp:arm_validator_reporters', '<(DEPTH)/native_client/src/trusted/validator_ragel/rdfa_validator.gyp:rdfa_validator']}]}]]} |
# Runtime: 156 ms
# Beats 72.62% of Python submissions
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def increasingBST(self, root):
"""
:type root: TreeNode
:rtype: TreeNode
"""
lst = []
lst = self.get_inorder(root, lst)
if lst:
root_ret = TreeNode(lst[0])
root_backup = root_ret
if len(lst) > 1:
for elem in lst[1:]:
root_ret.right = TreeNode(elem)
root_ret = root_ret.right
return root_backup
def get_inorder(self, root, lst):
if root:
self.get_inorder(root.left, lst)
lst.append(root.val)
self.get_inorder(root.right, lst)
return lst | class Solution:
def increasing_bst(self, root):
"""
:type root: TreeNode
:rtype: TreeNode
"""
lst = []
lst = self.get_inorder(root, lst)
if lst:
root_ret = tree_node(lst[0])
root_backup = root_ret
if len(lst) > 1:
for elem in lst[1:]:
root_ret.right = tree_node(elem)
root_ret = root_ret.right
return root_backup
def get_inorder(self, root, lst):
if root:
self.get_inorder(root.left, lst)
lst.append(root.val)
self.get_inorder(root.right, lst)
return lst |
def popup_element(value, title=None, format=None):
"""Helper function for quickly adding a popup element to a layer.
Args:
value (str): Column name to display the value for each feature.
title (str, optional): Title for the given value. By default, it's the name of the value.
format (str, optional): Format to apply to number values in the widget, based on d3-format
specifier (https://github.com/d3/d3-format#locale_format).
Example:
>>> popup_element('column_name', title='Popup title', format='.2~s')
"""
return {
'value': value,
'title': title,
'format': format
}
| def popup_element(value, title=None, format=None):
"""Helper function for quickly adding a popup element to a layer.
Args:
value (str): Column name to display the value for each feature.
title (str, optional): Title for the given value. By default, it's the name of the value.
format (str, optional): Format to apply to number values in the widget, based on d3-format
specifier (https://github.com/d3/d3-format#locale_format).
Example:
>>> popup_element('column_name', title='Popup title', format='.2~s')
"""
return {'value': value, 'title': title, 'format': format} |
# Create a list of strings: fellowship
fellowship = ['frodo', 'samwise', 'merry', 'aragorn', 'legolas', 'boromir', 'gimli']
# Create list comprehension: new_fellowship
new_fellowship = [member if len(member) >= 7 else "" for member in fellowship]
# Print the new list
print(new_fellowship) | fellowship = ['frodo', 'samwise', 'merry', 'aragorn', 'legolas', 'boromir', 'gimli']
new_fellowship = [member if len(member) >= 7 else '' for member in fellowship]
print(new_fellowship) |
#string literals
print('this is a sample string')
#concatenation - The print() function inserts a space between elements separated by a comma.
name = "Zen"
print("My name is", name)
#The second is by concatenating the contents into a new string, with the help of +.
name = "Zen"
print("My name is " + name)
number = 5
print('My number is', number)
# print('My number is'+ number) throws an error
# Type Casting or Explicit Type Conversion
# print("Hello" + 42) # output: TypeError
print("Hello" + str(42)) # output: Hello 42
total = 35
user_val = "26"
# total = total + user_val output: TypeError
total = total + int(user_val) # total will be 61
# f-strings: Python 3.6 introduced f-strings for string interpolation. To construct a f-string, place an f right before the opening quotation. Then within the string, place any variables within curly brackets.
first_name = "Zen"
last_name = "Coder"
age = 27
print(f"My name is {first_name} {last_name} and I am {age} years old.")
# string.format() Prior to f-strings, string interpolation was accomplished with the .format() method.
first_name = "Zen"
last_name = "Coder"
age = 27
print("My name is {} {} and I am {} years old.".format(first_name, last_name, age))
# output: My name is Zen Coder and I am 27 years old.
print("My name is {} {} and I am {} years old.".format(age, first_name, last_name))
# output: My name is 27 Zen and I am Coder years old.
# %-formatting - an even older method, the % symbol is used to indicate a placeholder, a %s for a string and %d for a number.
hw = "Hello %s" % "world" # with literal values
py = "I love Python %d" % 3
print(hw, py)
# output: Hello world I love Python 3
name = "Zen"
age = 27
print("My name is %s and I'm %d" % (name, age)) # or with variables
# output: My name is Zen and I'm 27
# Built in methods
x = "hello world"
print(x.title())
# output:
"Hello World"
| print('this is a sample string')
name = 'Zen'
print('My name is', name)
name = 'Zen'
print('My name is ' + name)
number = 5
print('My number is', number)
print('Hello' + str(42))
total = 35
user_val = '26'
total = total + int(user_val)
first_name = 'Zen'
last_name = 'Coder'
age = 27
print(f'My name is {first_name} {last_name} and I am {age} years old.')
first_name = 'Zen'
last_name = 'Coder'
age = 27
print('My name is {} {} and I am {} years old.'.format(first_name, last_name, age))
print('My name is {} {} and I am {} years old.'.format(age, first_name, last_name))
hw = 'Hello %s' % 'world'
py = 'I love Python %d' % 3
print(hw, py)
name = 'Zen'
age = 27
print("My name is %s and I'm %d" % (name, age))
x = 'hello world'
print(x.title())
'Hello World' |
EXPIRED_UPDATE = 240
CLUMP_TIMEOUT = 1
ACTIVE_TIMEOUT = 0.005
BULK_BOUND = 4
| expired_update = 240
clump_timeout = 1
active_timeout = 0.005
bulk_bound = 4 |
KEEP_RATE = 0.8 #Rate of dropping out in the dropout layer
LOG_DIR = "../ops_logs" #Directory where the logs would be stored for visualization of the training
#Neural network constants
cat1_dir = "../categories/treematter/ingroup/"
cat2_dir = "../categories/plywood/ingroup/"
cat3_dir = "../categories/cardboard/ingroup/"
cat4_dir = "../categories/bottles/ingroup/"
cat5_dir = "../categories/trashbag/ingroup/"
cat6_dir = "../categories/blackbag/ingroup/"
CAT1 = "treematter"
CAT2 = "plywood"
CAT3 = "cardboard"
CAT4 = "bottles"
CAT5 = "trashbag"
CAT6 = "blackbag"
CAT1_ONEHOT = [1,0,0,0,0,0]
CAT2_ONEHOT = [0,1,0,0,0,0]
CAT3_ONEHOT = [0,0,1,0,0,0]
CAT4_ONEHOT = [0,0,0,1,0,0]
CAT5_ONEHOT = [0,0,0,0,1,0]
CAT6_ONEHOT = [0,0,0,0,0,1]
LEARNING_RATE = 0.001 #Learning rate for training the CNN
CNN_LOCAL1 = 64 #Number of features output for conv layer 1
CLASSES = 6
CNN_EPOCHS = 10000
CNN_FULL1 = 200 #Number of features output for fully connected layer1
FULL_IMGSIZE = 500
IMG_SIZE = 28
IMG_DEPTH = 3
BATCH_SIZE = 300
MIN_DENSITY = 10000
SPATIAL_RADIUS = 5
RANGE_RADIUS = 5
| keep_rate = 0.8
log_dir = '../ops_logs'
cat1_dir = '../categories/treematter/ingroup/'
cat2_dir = '../categories/plywood/ingroup/'
cat3_dir = '../categories/cardboard/ingroup/'
cat4_dir = '../categories/bottles/ingroup/'
cat5_dir = '../categories/trashbag/ingroup/'
cat6_dir = '../categories/blackbag/ingroup/'
cat1 = 'treematter'
cat2 = 'plywood'
cat3 = 'cardboard'
cat4 = 'bottles'
cat5 = 'trashbag'
cat6 = 'blackbag'
cat1_onehot = [1, 0, 0, 0, 0, 0]
cat2_onehot = [0, 1, 0, 0, 0, 0]
cat3_onehot = [0, 0, 1, 0, 0, 0]
cat4_onehot = [0, 0, 0, 1, 0, 0]
cat5_onehot = [0, 0, 0, 0, 1, 0]
cat6_onehot = [0, 0, 0, 0, 0, 1]
learning_rate = 0.001
cnn_local1 = 64
classes = 6
cnn_epochs = 10000
cnn_full1 = 200
full_imgsize = 500
img_size = 28
img_depth = 3
batch_size = 300
min_density = 10000
spatial_radius = 5
range_radius = 5 |
class Solution:
def numDistinct(self, s: str, t: str) -> int:
dp = []
for i in range(len(s) + 1):
dp.append([0] * (len(t) + 1))
dp[0][0] = 1
for i in range(len(s) + 1):
dp[i][0] = 1
for a in range(1, len(t) + 1):
for b in range(a, len(s) + 1):
if s[b - 1] == t[a - 1]:
dp[b][a] = dp[b - 1][a - 1] + dp[b - 1][a]
else:
dp[b][a] = dp[b - 1][a]
return dp[-1][-1] | class Solution:
def num_distinct(self, s: str, t: str) -> int:
dp = []
for i in range(len(s) + 1):
dp.append([0] * (len(t) + 1))
dp[0][0] = 1
for i in range(len(s) + 1):
dp[i][0] = 1
for a in range(1, len(t) + 1):
for b in range(a, len(s) + 1):
if s[b - 1] == t[a - 1]:
dp[b][a] = dp[b - 1][a - 1] + dp[b - 1][a]
else:
dp[b][a] = dp[b - 1][a]
return dp[-1][-1] |
class Solution:
def peakIndexInMountainArray(self, A):
"""
:type A: List[int]
:rtype: int
"""
# return A.index(max(A))
return max(range(len(A)), key=A.__getitem__)
| class Solution:
def peak_index_in_mountain_array(self, A):
"""
:type A: List[int]
:rtype: int
"""
return max(range(len(A)), key=A.__getitem__) |
expected_output = {
"outside": {
"ipv4": {
"neighbors": {
"10.10.1.1": {
"ip": "10.10.1.1",
"link_layer_address": "aa11.bbff.ee55",
"age": "alias",
},
"10.10.1.1/1": {
"ip": "10.10.1.1",
"prefix_length": "1",
"link_layer_address": "aa11.bbff.ee55",
"age": "-",
},
}
}
},
"pod100": {
"ipv4": {
"neighbors": {
"10.10.1.1": {
"ip": "10.10.1.1",
"link_layer_address": "aa11.bbff.ee55",
"age": "2222",
}
}
}
},
}
| expected_output = {'outside': {'ipv4': {'neighbors': {'10.10.1.1': {'ip': '10.10.1.1', 'link_layer_address': 'aa11.bbff.ee55', 'age': 'alias'}, '10.10.1.1/1': {'ip': '10.10.1.1', 'prefix_length': '1', 'link_layer_address': 'aa11.bbff.ee55', 'age': '-'}}}}, 'pod100': {'ipv4': {'neighbors': {'10.10.1.1': {'ip': '10.10.1.1', 'link_layer_address': 'aa11.bbff.ee55', 'age': '2222'}}}}} |
def Reverse(l):
newL = []
for i in range(len(l)):
index = len(l) - i - 1 #Trying to make for(int i=l.length()-1; i>=0; i--) but in python
newL.insert(i, l[index])
return newL
l = [1,2,3,4,5,6,7,8,9,10]
new_l = Reverse(l)
print(new_l) | def reverse(l):
new_l = []
for i in range(len(l)):
index = len(l) - i - 1
newL.insert(i, l[index])
return newL
l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
new_l = reverse(l)
print(new_l) |
class Utilities:
@staticmethod
def swap(a, b, arr):
arr[a], arr[b] = arr[b], arr[a]
return arr
| class Utilities:
@staticmethod
def swap(a, b, arr):
(arr[a], arr[b]) = (arr[b], arr[a])
return arr |
class Solution:
def kidsWithCandies(self, candies: list[int], extraCandies: int) -> list[bool]:
result = list(map(lambda x: True if x+extraCandies >=
max(candies) else False, candies))
return result
# Time Complexity = O(1) | class Solution:
def kids_with_candies(self, candies: list[int], extraCandies: int) -> list[bool]:
result = list(map(lambda x: True if x + extraCandies >= max(candies) else False, candies))
return result |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.